title: delete alternate nodes in linked list in java
body: <p>I am writing code for deleteing alternate nodes in linked list. why it goes in infinite loop ?
  Input : 5->11->13->12->15->5 
  Expected op : 5->13->15->5 </p>
  
  <pre><code>public Node deleteAlternate(Node head)
  {
      Node p = head;
      Node q = head.next;
  
      while(q!=null &amp;&amp; q.next !=null)
      {
          p.next = q.next;
          q.next = p ;
          p.next = q;
  
          System.out.println(p.data+"   "+q.data);
      }
      return head;
  }
  </code></pre>
  
  <blockquote>
    <p>Blockquote</p>
  </blockquote>