title: Deletion at end in linked lists
body: <p>i am trying to write a simple program for deletion and insertion at the end of a linked list. I have managed to insert values at the end perfectly but I cannot understand what to do in deletion.</p>
  
  <p>The delete function is <code>deleteend()</code>, display function is <code>display()</code> and insert function is <code>insertend(int x)</code> but I have problem only with <code>delteend()</code>.</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  struct node
  {
      int info;
      node *next;
  };
  node *head = NULL;
  void insertend(int x)
  {
      node *last = new node;
      last-&gt;info = x;
      last-&gt;next = NULL;
      if (head == NULL)
          head=last;
      else
      {
          node *temp=head;
          while(temp-&gt;next!=NULL)
              temp=temp-&gt;next;
          temp-&gt;next=last;
      }
  }
  
  void display()
  {
      node *np=head;
      while(np!=NULL)
      {
          cout&lt;&lt;np-&gt;info&lt;&lt;endl;
          np=np-&gt;next;
      }
  }
  
  void deleteend()
  {
      node *temp=head;
      while(temp-&gt;next!=NULL)
          temp=temp-&gt;next;
      delete temp;
  }
  
  int main()
  {
      int data;
      char ch;
      do
      {
          cout&lt;&lt;"Enter value:";cin&gt;&gt;data;
          cout&lt;&lt;endl;
          insertend(data);
          cout&lt;&lt;"Enter more values?(y/n):";cin&gt;&gt;ch;
          cout&lt;&lt;endl;
      } while(ch=='y');
      cout&lt;&lt;"Your list is"&lt;&lt;endl;
      display();
      do
      {
          cout&lt;&lt;"Delete value from end?(y/n):";cin&gt;&gt;ch;
          cout&lt;&lt;endl;
          if(ch=='y')
              deleteend();
      } while(ch=='y');
      cout&lt;&lt;"Your list is"&lt;&lt;endl;
      display();
      return 0;
  }
  </code></pre>