leetcode swap nodes in pairs
class Solution { public: ListNode *swapPairs(ListNode *head) { if(head==NULL)return NULL; ListNode *p=head,*ppre=head,*pnext; while(p&&p->next) { pnext=p->next; if(pnext) { if(ppre==head)head=pnext; else ppre->next=pnext; p->next=pnext->next; pnext->next=p; ppre=p; p=p->next; } } return head; } };