title: Linked List implementation of Stack Deletion Error Using Pop
body: <p>Guys I am a newbie and i am learning data structures.I am learning Linked list implementation of stack and I wrote this code below for the implementation.
  the push method works fine but the pop method doesnt works fine and doesnt deletes the node.</p>
  
  <pre><code>public class Slink {
      Node head;
      public void push(int data)
      {
          Node node =new Node();
          node.data=data;
          node.next=null;
          if(head==null)
          {
              head=node;
  
          }
          else
          {
              Node n=head;
              while (n.next!=null)
              {
                  n=n.next;
              }
              n.next=node;
          }
  
      }
      public void pop()
      {
          if(head==null)
          {
              System.out.println("Stack has 0 items .. cant delete");
          }
          else {
              Node n = head;
              while (n.next != null) {
                  n = n.next;
              }
              n=null;
  
  
          }
      }
      public void show()
      {
          Node n=head;
          while(n.next!=null)
          {
              System.out.println(n.data);
              n=n.next;
          }
          System.out.println(n.data);
      }
  }
  </code></pre>
  
  <p>Now using this in a class.</p>
  
  <pre><code>public class Sll {
      public static void main(String[] args) {
          Slink stk=new Slink();
          stk.push(4);
          stk.push(54);
  
          stk.push(23);
          stk.push(90);
  
          stk.pop();
  
          stk.show();
  
      }
  }
  </code></pre>
  
  <p>The output is 
  4
  54
  23
  90</p>
  
  <p>while 90 should have been removed.
  Guys please tell me where i am wrong and correct me.
  Thanks</p>