欢迎使用CSDN-markdown编辑器

kernel struct list_head结构体介绍
1/ 注册节点
LIST_HEAD(struct list_head *head); // 新建一个head的结构体,然后初始化
INIT_LIST_HEAD(struct list_head *head); //初始化head,注意head是提前定义好的.

2/ 增加节点
list_add(struct list_head *new, struct list_head *head); //将new 添加到head->next 相当于head链表的第一个元素.head本身不是元素.
list_add_tail(struct list_head *new, struct list_head *head); //将new 添加到head->prev 相当于head链表的最后一个元素

3/ 删除节点
list_del(struct list_head *head); //将head从所在的链表中删除.head->prev head->next 赋值为无效的值

4/ 遍历链表

define list_entry(ptr, type, member) container_of(ptr, type, member)

define list_for_each(pos, struct list_head *head) \

for(pos = head->next; pos != head; pos = pos->next)

exp:
struct student {
char name[50];
struct list_head list;
};

struct list_head *pos;
list_for_each(pos, head) {
struct student * pStu = list_entry(pos, struct student, list);
}

5/ 判断是否为空
list_empty(struct list_head *head);

参考代码:https://github.com/generalharry/kernel_list_head/tree/master

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值