我写了程序,老师要求用链表。结果出了个问题怎么也改不了。提示说INSERT函数有问题。大家帮忙看看?
#define NULL0 #define LEN sizeof (struct student) #include <stdio.h> struct student {long num; char name [20]; char sex; int age; float score [10] ; struct students*next; }; int n ,i, score [10]; struct student*create() {struct student *head,*p1,*p2; n=0; head=NULL; p1=(struct student *)malloc(LEN); scanf("%d%c%c%d",&p1->num,p1->name[20],&p1->sex,&p1->age); for(i=0;i<10;i++) {scanf("%d",&score[i]);}; p1->next=NULL; while(p1->num!=0) {++n; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(struct student*)malloc(LEN); scanf("%d%c%c%d",&p1->num,p1->name[20],&p1->sex,&p1->age); for(i=0;i<10;i++) scanf("%d",&score[i]); p1->next=NULL; }free(p1); return(head); } struct student *insert(struct student *head,struct student *stud) {struct student *p0,*p1,*p2; p1=head; p0=stud; if(head==NULL) {head=p0;p0->next=NULL;} else {while((p0->num>p1->num)&&(p1!=NULL)) {p2=p1;p1=p1->next;} if(head==p1) {head=p0; p0->next=head;} else
{p2->next=p0; p0->next=p1; } ++n; return (head); } struct student *delete(struct student *head,long num) {struct student *p1,*p2; if(head==NULL) goto end; else p1=head; while((num!=p1->num)&&(p1->next!=NULL)) {p2=p1;p1=p1->next;} if(num==p1->num) {if(p1==head) head=p1->next; else p2->next=p1->next; printf("delete:%d\n",num); free(p1); n--; } else printf("%d not been found!\n",num); end:return(head); } struct student *find(struct student *head,long num) {struct student p1,*p2; int i; if(head==NULL) {printf("\n list NULL!\n");goto end;} p1=head; while((num!=p1->num)&&(p1!=NULL)) {p2=p1;p1=p1->next;} if(p1!=NULL) {printf("find:%d%c%c%d",num,name,sex,age); for(i=0;i<10;i++) printf("%d",score[i]); } else printf("%d not been found!\n",num); end: return(head); } float aver(float score[]) {int i; for(i=0;i<10;i++) aver+=score[i]; aver=aver/10; return(aver); } float highest(float score[]) {int i; highest=score[0]; for(i=1;i<10;i++) {if(score[i]>highest) highest=score;} return(highest); } float lowest(float score[]) {int i; lowest=score[0]; for(i=1;i<10;i++) {if(lowest>score[i]) lowest=score[i]; } return lowest; } main() {char a; printf("Welcome to students' MIS!\n"); scanf("%c",&a); switch(a) {case I:struct student*insert(struct student*head,struct student*stud);break; case D:struct student*delete(struct student*head,long num);break; case F:struct student*find(struct student*head,long num);break; case C:float aver(float score[])}; float highest(float score[]); float lowest(float score[]);break; case Q:printf("\n"); } }