C语言 NOTE29

双向内核循环链表:

  • 在一个链表结构体里内嵌一个指针域结构体small_list , 其成员有前驱指针和后继指针但指向的不再是大的结构体,而是small_list。
    在这里插入图片描述
    定义结构体:
typedef struct DOU_KEL_NODE_LIST
{
	struct list_head small_list; 
	int data;
}Dou_Kel_Node_List, *PDou_Kel_Node_List;
struct list_head
{
	struct list_head *prev;
	struct list_head *next;
};

  • 重要:如何通过small_list来获取大结构体地址?

在这里插入图片描述

p = (PDou_Kel_Node_List)((char*)((head->small_list).next)-(unsiged long)&((PDou_Kel_Node_List)0->small_list))
发布了52 篇原创文章 · 获赞 2 · 访问量 1997

猜你喜欢

转载自blog.csdn.net/weixin_42191545/article/details/103981459