/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ ListNode* Merge(ListNode* pHead1, ListNode* pHead2) //将两个非递减链表,合并为一个非递减链表并返回 { if(pHead1 == NULL) return pHead2; if(pHead2 == NULL) return pHead1; ListNode* new_List; ListNode* new_Head; if(pHead1->val < pHead2->val) { new_Head = pHead1; pHead1 = pHead1->next; } else { new_Head = pHead2; pHead2 = pHead2->next; } new_List = new_Head; while(pHead1!=NULL && pHead2!=NULL) { if(pHead1->val < pHead2->val) { new_List->next = pHead1; new_List = pHead1; pHead1 = pHead1->next; } else { new_List->next = pHead2; new_List = pHead2; pHead2 = pHead2->next; } } new_List->next = pHead1?pHead1:pHead2; return new_Head; }