void MergeList(Linklist La,Linklist Lb,Linklist *Lc)
{
Linklist pa,pb,pc,q;
pa=La->next;
pb=Lb->next;
(*Lc)=pc=La;
while(pa && pb)
{
if(pa->data<pb->data)
{
pc->next=pa;
pc=pa;
pa=pa->next;
}
else if(pa->data>pb->data)
{
pc->next=pb;
pc=pb;
pb=pb->next;
}
else
{
pc->next=pa;
pc=pa;
pa=pa->next;
q=pb->next;
free(pb);
pb =q;
}
}
pc->next=pa?pa:pb;
free(Lb);
}
int main()
{
int a[5]={1,3,12,13,14};
int b[5]={2,4,6,8,10};
Linklist L1;
Linklist L2;
Linklist L3;
int i;
L1 = (Lnode*)malloc(sizeof(Lnode));
L1->next = NULL;
L1->data = 0;
L2 = (Lnode*)malloc(sizeof(Lnode));
L2->next = NULL;
L2->data = 0;
L3 = (Lnode*)malloc(sizeof(Lnode));
L3->next = NULL;
L3->data = 0;
for(i=0;i<5;i++){
Linklist_biu(L1,a[i]);
Linklist_biu(L2,b[i]);
}
Linklist_print(L1);
Linklist_print(L2);
MergeList(L1,L2,&L3);
Linklist_print(L3);
return 0;
}