关于链表建立的问题,求高手。。
N名学生的成绩在主函数中放入一个带头节点(头节点包括学号、成绩、姓名和下一个节点的指针)的链表结构中,创建节点时可以直接指定节点成员数值。h指向链表的头节点。请编写函数fun,它的功能是:找出学生的最高分,由函数值返回。主函数中调用该函数测试函数功能。程序代码:
#include<stdio.h> #include<stdlib.h> #include<conio.h> #define NULL 0 double fun(struct st a,struct st b,struct st c); struct st { long num; double gra; char n[20]; struct st *next; }; int main() { struct st a,b,c, *head,*p; double i; //第1个学生 printf("please input No.1 student's name:\n"); gets(a.n); printf("please input No.1 student's number:\n"); scanf("%ld",&a.num); printf("please input No.1 student's grade:\n"); scanf("%f",&a.gra); //第2个学生 printf("please input No.2 student's name:\n"); gets(b.n); printf("please input No.2 student's number:\n"); scanf("%ld",&b.num); printf("please input No.2 student's grade:\n"); scanf("%f",&b.gra); //第3个学生 printf("please input No.3 student's name:\n"); gets(c.n); printf("please input No.3 student's number:\n"); scanf("%ld",&c.num); printf("please input No.3 student's grade:\n"); scanf("%f",&c.gra); head=&a; a.next=&b; b.next=&c; c.next=NULL; p=head; i=fun(a,b,c); printf("the highest score is %ld",i); return 0; } double fun(struct st a,struct st b,struct st c) { double m; if(a.gra>=b.gra) m=a.gra; else m=b.gra; if(m<c.gra) m=c.gra; return m; }
运行后自动跳过了输入学生2和学生3的名字的过程。。。求解啊。。