0
点赞
收藏
分享

微信扫一扫

链表学习(一)静态链表的构造


#include<stdio.h>

typedef struct Student //声明结构体类型 struct Student

{
int num;
float score;
struct Student *next;
} stu ;

int main()
{
//定义5个结构体变量,a,b,c作为链表的节点,
//定义head和p 是指向struct Student 结构体型数据的指针变量
stu a,b,c,*head,*p;
//对节点a,b,c的成员进行赋值
a.num=10101;a.score=89.5;
b.num=10103;b.score=90;
c.num=10107;c.score=85;
//将a的起始地址赋给头指针head
head=&a;

//将b的起始地址赋给a节点的next成员
a.next=&b;
//将c的起始地址赋给b节点的next成员
b.next=&c;

//c节点的next成员不存放其他节点地址
c.next=NULL;

//使p指向节点a
p=head;
do
//输出p指向节点的数据
{ printf("%1d%5.1f\n",p->num,p->score);
//使p指向下一个节点
p=p->next;
} while(p!=NULL);//输出完最后一个节点后,循环终止
return 0;
}

10101 89.5
10103 90.0
10107 85.0


举报

相关推荐

0 条评论