C语言学习016:单链表

 1 #include <stdio.h>
 2 
 3 //定义一个链表,链表是一种递归结构,在定义的时候必须要给结构起一个名字
 4 typedef struct folder{
 5     int level;
 6     char* filename;
 7     struct folder* child;//通过指针链接下一个结构
 8 }folder;
 9 
10 int main(){
11     folder first={1,"first",NULL};
12     folder second={2,"second",NULL};
13     folder thread={3,"thread",NULL};
14     first.child=&second;
15     second.child=&thread;
16     folder* i=&first;
17     for(;i!=NULL;i=i->child){
18         printf("%s level is %i \n",i->filename,i->level);
19     }
20     return 0;
21 }

  在链表中插入值,只需要修改指针的值就行

    second.child=&thread;
    folder fourth={4,"fourth",NULL};

  链表相对于数组而言,插入数据非常快,但是如果有一个很长的链表,要想访问最后一个元素,你需要从第一个开始一层一层的读下去,而数组可以通过索引直接访问元素,所以使用数组还是链表需要根据环境来决定

转载于:https://www.cnblogs.com/liunlls/p/C_list.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值