1 typedef struct Node{
2 int data;
3 struct Node* next;
4 }Node, *LinkList;
5 void Merge(LinkList la, LinkList lb, LinkList &lc)
6 {
7 // NULL检测
8 if(!la) {lc = pb; return;}
9 if(!lb) {lc = pa; return;}
10 Node* p;
11
12 // 确定最大值在la上, 还是lb上
13 if(la.data > lb.data) { lc = p = la; la = la->next; }
14 else { lc = p = lb; lb = lb->next; }
15
16 while(la &&lb)
17 {
18 if(la.data > lb.data)
19 {
20 p->next = la;
21 la = la->next;
22 }else if(la.data < lb.data)
23 {
24 p->next = lb;
25 lb = lb->next;
26 }else{ // la 与 lb中值相等的情况
27 p->next = la;
28 la = la->next;
29 Node* tmp = lb;
30 lb = lb->next;
31 free(tmp);
32 }
33 p = p->next;
34 }
35 // 剩余部分链表的挂接
36 p->next = (la ? la:lb);
37 }