All we need to do is rearrange the links in the list.If **prev ** is the pevious node,** head ** is the current node,at every alternate node perform operations such that

Initial: prev | head | head->next|head->next->next

After swap:prev|head->next|head|head->next->next

```
ListNode* swapPairs(ListNode* head) {
ListNode* dummy=new ListNode(0);
dummy->next=head;
ListNode* prev=dummy;
while(head &&head->next)
{
ListNode* nn=head->next->next;
prev->next=head->next;
head->next->next=head;
head->next=nn;
prev=head;
head=nn;
}
return dummy->next;
}
```