设计两个有序单链表的合并排序算法
ListList MergeList(LiskList La, LinkList Lb){
Lnode *pa = La->next;
Lnode *pb = Lb->next;
if(Lb->next == null)
return La;
if(La->next == null)
return Lb;
LinkList Lc = (LinkList)malloc(sizeof(Lnode));
Lnode *r = Lc; //采用尾插法
While(pa && pb){ //如果循环停止,则La或Lb至少有一个为NULL
if(pa ->data <= pb->data){
r->next = pa;
r = pa;
pa = pa->next;
}else{
r->next = pb;
r = pb;
pb = pb->next;
}
}
While(pa){ //如果La还没走完
r->next = pa;
r = pa;
pa = pa->next;
}
While(pb){ //如果Lb还没走完
r->next = pb;
r = pb;
pb = pb->next;
}
r->next = null;
return Lc;
}