[LeetCode]Swap Nodes in Pairs

It's pretty simple

class Solution {  
public:  
    ListNode* swapPairs(ListNode* head) {
        ListNode *p1, *p, *beforehead;

        beforehead = new ListNode(0);
        beforehead->next = head;

        p = beforehead;
        while(p->next != NULL && p->next->next != NULL) {
            p1 = p->next;
            p->next = p1->next;
            p1->next = p->next->next;
            p->next->next = p1;
            p = p1;
        }

        return beforehead->next;
    }
};