#include
#include
struct stu
{
int num;
struct stu next;
};
struct stu creat(void)//建立一个链表
{
int n;
struct stu p1,*p2,*head;
scanf("%d",&n);
p1=head=(struct stu *)malloc(sizeof(struct stu));
p1->next=NULL;
for(int i=0;i
{
p2=(struct stu *)malloc(sizeof(struct stu));
p2->next=NULL;
scanf("%d",&p2->num);
p1->next=p2;
p1=p2;
}
p1->next=NULL;
return head;
}
int main()
{
struct stu *p1,*pt_a,*pt_b;
struct stu head=(struct stu *)malloc(sizeof(struct stu));新链表的表头
p1=head;
p1->next==NULL;
pt_a=creat();
pt_b=creat();
while(pt_a->next&&pt_b->next)//判断一个链表是否遍历到结尾
{
if(pt_a->next->num>pt_b->next->num);判断大小
{
p1->next=pt_b->next;连接到新链表上
p1=pt_b->next;新表指针指向最后一个
pt_b=pt_b->next;原先的链表后移
}
经过调试发现旧链表不会后移,所以一直死循环
else{
p1->next=pt_a->next;
p1=pt_a->next;
pt_a=pt_a->next;
}
}
p1->next=NULL;
while(head->next!=NULL)
{
printf("%5d",head->next->num);
head=head->next;
}
return 0;
}