http://oj.leetcode.com/problems/swap-nodes-in-pairs/
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *swapPairs(ListNode *head) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if(head==NULL) return NULL;
if(head->next==NULL) return head;
ListNode *newHead=head->next;
ListNode *nextHead=newHead->next;
newHead->next=head;
head->next=swapPairs(nextHead);
return newHead;
}
};