title: swapping adjacent nodes of a LinkedList
body: <p>I have to swap two adjacent node(not their data) in a linked list.
  e.g.
  1) Input a->b->c->d->e->f, Output : b->a->d->c->f->e
  2) Input a->b->c->d->e, Output : b->a->d->c->e</p>
  
  <p>I have writen the following code is there any more efficient way (maybe with two temporary pointers) or simple logic?</p>
  
  <pre><code>node* swap(node* head) {
     node *first = head;
     node *second,*third,*result;
  
     if(head == NULL || head-&gt;next == NULL) {
          return head;
     }
  
      result = second = first-&gt;next;
      third = second-&gt;next;
  
      while(second != NULL) {
         second-&gt;next=first;
         first-&gt;next=(third-&gt;next==NULL ? third : third-&gt;next);
         first=third;
         second=(third-&gt;next==NULL ? third : third-&gt;next);
         third=(second==NULL ? second : second-&gt;next);
      }
      return result;
  }
  </code></pre>