合并双链表

/*
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
            val(x), next(NULL) {
    }
};*/
class Solution {
  public:
    ListNode* Merge(ListNode* pHead1, ListNode* pHead2) {
        ListNode* head = new ListNode(0), *cur = head;

        ListNode* p = pHead1, *q = pHead2,*t=NULL;

        while (p != NULL && q != NULL) {
            int v1 = p->val;
            int v2 = q->val;
            if (v1 < v2) {
                t=p->next;
                cur->next = p;
                cur = p;
                p = t;
            } else {
                t=q->next;
                cur->next = q;
                cur = q;
                q = t;
            }
        }
        if (p != NULL) {
            cur->next = p;
        }
        if (q != NULL) {
            cur->next = q;
        }
        return head->next;
    }
};