案例:有三个学生,每名学生有三门科成绩,要求输出平均成绩最高的学生的全部信息,用动态链表存储学生信息
代码1:
#include “stdio.h”
#include “string.h”
#include “stdlib.h”
struct Student{
int number;
char name[20];
double score[3];
double average;
};
struct Node{
struct Student stu;
struct Node *next;
};
void main(){struct Node *head=NULL,*n,*p,*max;
int i;
for(i=0;i<3;i++){
n=(struct Node *)malloc(sizeof(struct Node));
scanf("%d%s%lf%lf%lf",&n->stu.number,n->stu.name,&n->stu.score[0],&n->stu.score[1],&n->stu.score[2]);
(*n).next=NULL;
if(head==NULL)
{p=n;
head=n;}
else{p->next=n;
p=n;}
}
for(p=head;p!=NULL;p=p->next)
{
p->stu.average=(p->stu.score[0]+p->stu.score[1]+p->