思路:穿针引线
ListNode* MergeTwoList(linkList headA, linkList headB) { ListNode* pa = headA; ListNode* pb = headB; ListNode* headC = (ListNode*)malloc(sizeof(ListNode)); ListNode* pc = headC; pc->next = NULL; while (pa != NULL && pb != NULL) { if (pa->data <= pb->data) { pc->next = pa; pa = pa->next; } else { pc->next = pb; pb = pb->next; } pc = pc->next; } if (pa != NULL)pc->next = pa; if (pb != NULL)pc->next = pb; pc = headC; headC = pc->next; free(pc); return headC; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)