链表结合问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 03:04:54
结合两个链表,按升序排列,程序如下,但是结合不了,请高手指教,谢谢
#define null 0
#define len sizeof(struct student)
struct student
{
int num;
struct student *next;
};
int n;
struct student *creat()
{
struct student *head,*p1,*p2;
head=null;
printf("please input the link:");
p1=p2=(struct student*)malloc(len);
scanf("%d",&p1->num);
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(len);
scanf("%d",&p1->num);

}
p2->next=null;
return(head);
}
struct student * insert(struct student * head1,struct student * head2)
{
struct student *pa1,*pa2,*pb1,*pb2;
if(head1==null)
head1=head2;
else
{
pa2=pa1=head1;
pb2=pb1=head2;
while(pb1!=null)
{
while((pb1->num>pa1->num)&&(p

#define null 0
#define len sizeof(struct student)

struct student
{
int num;
struct student *next;
};

int n;

struct student *creat()
{
struct student *head,*p1,*p2;
head=null;
n=0;//全局量记得用完后要清空,我更不知道你在这为什么要用全局量
printf("please input the link:");
p1=p2=(struct student*)malloc(len);
scanf("%d",&p1->num);
while(p1->num!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student*)malloc(len);
scanf("%d",&p1->num);
}
p2->next=null;
return(head);
}

struct student * insert(struct student * head1,struct student * head2)
{
struct student *pa1,*pa2,*pb1,*pb2;
if(head1==null)
head1=head2;
else
{
pa1 = head1;
pa2 = head2;
while(pa1!=null)
{
pb1=pa1;
pa1=pa1->next;