#include <stdio.h>
struct Student
{ int num;
float score;
};
struct Node
{
struct Student stu;
struct Node *next;
};
int main()
{ struct Node a,b,c,*head,*p;
a.stu. num=10101; a.stu.score=89.5;
b.stu. num=10103; b.stu.score=90;
c.stu .num=10107; c.stu.score=85;
head=&a; a.next=&b;
b.next=&c; c.next=NULL;
p=head;
do
{printf("%ld%5.1f\n",p->stu.num,p->stu.score);
p=p->next;
}while(p!=NULL);
return 0;
}
结果显示
10101 89.5
10103 90.0
10107 85.0
注意:
struct Student
{ int num;
float score;
};
struct Node
{
struct Student stu;
struct Node *next;
};
可以改写为下面的格式
struct Student
{ int num;
float score;
struct Student *next;
};