代码如下:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
struct Student //学生结构体模型
{
int num;
float score;
struct Student* next;
};
int main()
{
struct Student a, b, c, * head, * p; //定义结构体变量a,b,c,头指针和指针p
a.num = 1001; b.num = 1002; c.num = 1003; //初始化三个学生的数据
a.score = 96.5; b.score = 90; c.score = 81;
head = &a; //表头
a.next = &b; //a的next指向下一个结点b
b.next = &c; //b的next指向下一个结点c
c.next = NULL; //c为表尾
p = head; //p指向头结点
while (p != NULL) //将链表输出
{
printf("%d %5.1f\n",p->num,p->score);
p = p->next;
}
printf("\n");
return 0;
}