class Solution {
public:
ListNode* swapPairs(ListNode* head) {
ListNode* dummyHead = new ListNode(0);
dummyHead->next = head;
ListNode* pre = dummyHead;
ListNode* cur = head;
while(cur!=NULL && cur->next!=NULL){
// 两个都不为NULL才会进行交换
ListNode* nxt = cur->next;
ListNode* tmp = nxt->next;
pre->next = nxt;
nxt->next = cur;
cur->next = tmp;
// 指针移动
pre = cur;
cur = cur->next;
}
return dummyHead->next;
}
};



