大神帮我看看这个关于链表的程序
#include<stdio.h>#include<stdlib.h>
struct student
{
int Xuehao;
int Score;
struct student *next;
};
typedef struct student Student;
Student *Create(void)
{
Student *head=NULL;
student *p1,*p2;
int n=0;
p1=p2=(Student *)malloc(sizeof(Student));
if(p1!=NULL)
{
n++;
printf("请输入第%d位同学的学号:\n",n);
scanf("%d",&(p1->Xuehao));
if(p1->Xuehao!=0)
{
printf("请输入第%d位同学的分数:\n",n);
scanf("%f",&(p1->Score));
head=p1;
}
else
{
free(p1);
return head;
}
}
else
return head;
while(1)
{
p1=(Student *)malloc(sizeof(Student));
if(p1!=NULL)
{
n++;
printf("请输入第%d位同学的学号:\n",n);
scanf("%f",&(p1->Xuehao));
if(p1->Xuehao!=0)
{
printf("请输入第%d位同学的分数:\n",n);
scanf("%f",&(p1->Score));
p2->next=p1;
p2=p1;
}
else
{
free(p1);
return p1->next=NULL;
return head;
}
}
}
}
void Print(Student *head)
{
Student *p=head;
printf("\n请输出数据:\n");
if(head!=NULL)
do
{
printf("%d\t%f\n",p->Xuehao,p->Score);
p=p->next;
}while(p!=NULL);
else
printf("此链表为空\n");
}
int main()
{
typedef struct student Student;
Student *Create(void);
void Print(Student *);
Student *head=NULL;
int k=0;
while(1)
{
printf("1——创建链表\n");
printf("2——输出链表\n");
printf("0——退出\n");
printf("请选择:");
scanf("%d\n",&k);
switch(k)
{
case 1: head=Create();continue;
case 2: Print(head);continue;
case 0: exit(0);
}
}
return 0;
}