title: swap pair elements in linked list implemented in Java
body: <p>I have written a code to <code>swap</code> elements of <code>linkedList</code> in <code>Java</code>.
  Currently, my code fails, i.e., it is not <code>swapping</code> elements. I am having difficulty
  on how to approach to this problem. Any tips?</p>
  
  <pre><code>public void switchPairs(){
      if (front==null || front.next==null)
          return ;
      ListNode temp=front;
      front=front.next;
      ListNode curr=front;
      while(curr.next!=null){
          ListNode dummy = curr.next;
          curr.next=temp;
          temp.next=dummy;
          temp=temp.next;
          curr=dummy;
      }
  }
  
  Input          : front -&gt; [3] -&gt; [7] -&gt; [4] -&gt; [9] -&gt; [8] -&gt; [12] / 
  Expected output: front -&gt; [7] -&gt; [3] -&gt; [9] -&gt; [4] -&gt; [12] -&gt; [8] /     
  my output:       front -&gt; [7] -&gt; [3] -&gt; [4] -&gt; [9] -&gt; [8] -&gt; [12] /
  </code></pre>