链表
是一种抽象的数据结构
使用场景
为了保存可变数量的数据,需要一样比数组更灵活的东西
工作原理
保存了一条数据和链向另一条数据的链接
创建链表
#include <stdio.h>
//注意要先定义函数在main函数的外部
void display();
//结构定义函数体的外面多个函数才能共享
typedef struct island {
char *name;
char *open;
char *close;
struct island *next;
} island;
int main()
{
island amity = {"Amity", "9:00", "17:00", NULL};
island craggy = {"craggy", "9:00", "17:00", NULL};
island shutter = {"shutter", "9:00", "17:00", NULL};
amity.next = &craggy;
craggy.next = &shutter;
display(&amity);
return 0;
}
void display(island *start) {
island *i = start;
for (;i!=NULL;i=i->next) {
printf("name:%s,open:%s-%s\n",i->name, i->open, i->close);
}
}
递归结构
如果一个结构中包含一个链向同种结构的链接,那么这个结构就被称为递归结构