问题描述
一个学生数据结构体可以有学号,成绩
我们需要定义一个链表,遍历输出各个数据
代码
#include<stdio.h>
//定义数据结构
typedef struct Student{
int num;
float score;
struct Student *next;//因为这个在里面还么有定义Stu
}Student;
int main()
{
Student a={1,98.2},b={2,78},c={3,89},d={4,68};//也可以通过a.num a.score 的方式赋值,
Student *p,*next,*head;
//链表连起来
head=&a;//逻辑上讲加上head表示头结点,然后p从头遍历,但也可以把p=&a效果一样
a.next=&b;
b.next=&c;
c.next=&d;
//遍历出来
int i;
p=head;
do{
printf("学号:%d成绩:%.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}