#include<stdio.h>
#include<string.h>
//定义一个结构体里面包含 学号 姓名 地址
struct Student
{
int num;
char name[20];
struct Student * next;
};
main()
{
struct Student stu[3];
struct Student * head,*p;
stu[0].num=001;
//字符数组赋值不能直接用 直接赋值 要用strcpy()
strcpy(stu[0].name,"hello1");
//stu[0].name="hello1";
stu[1].num=002;
strcpy(stu[1].name,"hello2");
//stu[1].name="hello2";
stu[2].num=003;
strcpy(stu[2].name,"hello3");
//stu[2].name="hello3";
head=&stu[0];
stu[0].next=&stu[1];
stu[1].next=&stu[2];
stu[2].next=NULL;
p=head;
do
{
printf("%d,%s\n",p->num,p->name);
p=p->next;
}while(p!=NULL);
return 0;
}
构建静态链表
最新推荐文章于 2022-10-21 20:21:22 发布