title: swapping adjacent nodes in a Linked list
body: <p>I have problems swapping adjacent nodes in a linkedlist.</p>
  
  <p>for ex:  input : 1->2->3->4->5->null
           output: 2->1->4->3->5->null</p>
  
  <pre><code>bool swapAdjacent(node** head)
  {
  
  //1-&gt;2-&gt;3-&gt;4-&gt;null
  
  //2-&gt;1-&gt;4-&gt;3-&gt;null
  if(head==NULL)
  return 0;
  node* current  = *head;
  *head = (*head)-&gt;next ;
  node* prev = NULL;
  cout&lt;&lt;"head val "&lt;&lt;(*head)-&gt;data &lt;&lt;endl;
  node* temp;
  while( current!=NULL&amp;&amp;current-&gt;next!=NULL)
  {
     temp = current-&gt;next ;  //1s pointer points to 2
     current-&gt;next = temp-&gt;next ;    // 1s pointer point to 3
     temp -&gt;next = current;   //2s pointer shud point to 1
     prev = current;
     current = current-&gt;next ;
     //cout&lt;&lt;"data " &lt;&lt;current-&gt;data &lt;&lt;endl;
  
     if(current!=NULL)
     prev-&gt;next = current-&gt;next ;
  
  
  
  }
  
  return 1;
  }
  </code></pre>
  
  <p>My code is not working whenever there are odd no of nodes. How to fix this ?</p>