没人帮忙哦,飞燕帮我来看下哪里错了啊
建立两个链表 a, b,每个链表中的节点包括学号、成绩。要求把两个链表合并,按学号升序排列。#include "stdio.h"
#include "malloc.h"
#define null 0
#define len sizeof(struct student)
int n;
struct student
{
long num;
long score;
struct student *next;
};
struct student *creat(void)
{
struct student *p1,*p2,*head;
head=null;
printf("please input the students' data:\n");
p1=p2=(struct student *)malloc(len);
scanf("%ld %ld",&p1->num,&p1->score);
n=0;
while(p1->num!=0)
{
n++;
if(n==1)head=p1;
else
{
p2->next=p1;
p2=p1;
}
p1=(struct student *)malloc(len);
scanf("%ld %ld",&p1->num,&p1->score);
}
p2->next=null;
return(head);
}
void print(struct student *head)
{
struct student *p;
p=head;
while(p!=null)
{
printf("%ld %ld\n",p->num,p->score);
p=p->next;
}
}
struct student *insert(struct student *head,struct student *p)
{
struct student *p1,*p2;
p1=p2=head;
if(head==null)head=p;
else
{
while(p->num>p1->num&&p1->next!=null)
{
p2=p1;p1=p1->next;
}
if(p->num<=p1->num)
{
if(p==head)
{
head=p;p1->next=p;
}
else
{
p2->next=p;p->next=p1;
}
}
else
{
p1->next=p;p->next=null;
}
n++;
}
return(head);
}
main()
{
struct student *a,*b,*p1;
a=creat();
print(a);
b=creat();
print(b);
p1=a;
while(p1!=null)
{
b=insert(b,p1);
p1=p1->next;
}
printf("the %d data:",n);
print(b);
}