合并两个递增有序链表
将两个递增的有序链表合并为一个递增的有序链表
LNode *Merge(LNode *L1,LNode *L2){
if(L1==0||L2==0) return 0;//若两表为空则返回空
if(L1->next==0) return L2; //表1为空直接返回表二
LNode *p=L1->next,*q=L2->next,*r=L1;
L1->next=0;
L2->next=0;
while(p&&q){
if(p->data<q->data){//p的值小于q的值
r->next=p;
r=p;
p=p->next;
}
else {
r->next=q;
r=q;
q=q->next;
}
}
if(p) r->next=p;//处理剩余结点
if(q) r->next=q;
free(L2);
return L1;
}