怎么实现两个升序的链表合并后还是升序的
怎么实现两个升序的链表合并后还是升序的放在原来的链表中
struct student *insert(struct student *ah,struct student *bh)
{
struct student *pa1,*pa2,*pb1,*pb2;
pa2=pa1=ah;
pb1=pb2=bh;
do
{
while((pb1->num>pa1->num)&&(pa1->next!=NULL))
{
pa2=pa1;
pa1=pa1->next;
}
if(pb1->num<=pa1->num)
{
if(ah==pa1)
ah=pb1;
else
pa2->next=pb1;
pb1=pb1->next;
pb2->next=pa1;
pa2=pb2;
pb2=pb1;
}
}while((pa1->next!=NULL)||(pa1==NULL&&pb1!=NULL));
if((pb1!=NULL)&&(pb1->num>pa1->num)&&(pa1->next==NULL))
pa1->next=pb1;
return (ah);
}
你参考下,估计对你会有帮助