/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ struct ListNode *mergeTwoLists(struct ListNode *list1, struct ListNode *list2) { struct ListNode **ppCur; for(ppCur = &list1; *ppCur; ppCur = &(*ppCur)->next) { if(!list2) break; while(list2 && list2->val < (*ppCur)->val) { struct ListNode *pTmp = list2->next; list2->next = *ppCur; *ppCur = list2; list2 = pTmp; } } if(list2) *ppCur = list2; return list1; }