List Merge(List L1,List L2)
{
List t1=L1->Next; List t2 =L2->Next;
List L=malloc(sizeof(struct Node));
L->Next=NULL;
List rear=L;
while(t1&&t2)
{
if(t1->Data > t2->Data)
{
rear->Next=t2;
rear=rear->Next;
t2=t2->Next;
}
else
{
rear->Next=t1;
rear=rear->Next;
t1=t1->Next;
}
}
if(t1==NULL)
{
rear->Next=t2;
L1->Next=NULL;
L2->Next=NULL;
return L;
}
if(t2==NULL)
{
rear->Next=t1;
L1->Next=NULL;
L2->Next=NULL;
return L;
}
L1->Next=NULL;
L2->Next=NULL;
rear->Next=NULL;
return L;
}
PAT-两个有序链表序列的合并
最新推荐文章于 2023-03-26 12:20:51 发布