核心雙向迴圈鍊錶

2021-07-02 20:52:39 字數 1668 閱讀 1855

#include

#include

#include

#include

#include

//煉表頭結構

struct list_head

;//真正實現鍊錶插入操作

void _list_add(struct list_head *nnew,struct list_head *prev,struct list_head *next)

void init_list_head(struct list_head *list)

//向鍊錶插入乙個節點

void list_add(struct list_head *nnew,struct list_head *head)

#define list_for_each(pos,head) \

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

#define list_for_each_safe(pos,n,head) \

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

//根據節點中的乙個成員在節點中的偏移量找到節點的起始位址

#define list_entry(ptr,type,member) \

((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

//真正實現鍊錶刪除操作

void _list_del(struct list_head *prev,struct list_head *next)

//刪除鍊錶中的乙個節點

刪除節點後,核心原始操作會將兩個指標指向自己,這個在實際運用的時候可能會出錯,新分配的記憶體正好分陪到之前釋放的節點的記憶體,會使得新的節點自己指向自己,導致死迴圈,

void list_del(struct list_head *entry)

#define server_group_name_size 32

#define max_server_group_size 128

typedef struct server_info ;

}server_info_t;

typedef struct server_group 

ser_group_t;

ser_group_t * g_ser_t;

void list_init()

/*insert link*/

void add_list(ser_group_t* server_new_data)

void node_find(ser_group_t* sernode_find)

}void node_delete(ser_group_t* sernode_del)

#endif

/*刪除乙個節點*/

list_for_each_safe(pos, t, &g_ser_t->list)  */

}}int main()

;test.count = 1;

list_init();

add_list(&test);

node_find(&test);

return 0;

}

linux核心雙向迴圈鍊錶例項

ifndef list h define list h 核心裡的雙向迴圈鍊錶 是乙個只有指標域而沒有資料域的結構 struct list define list head init name define list head name struct list name list head init ...

雙向鍊錶和雙向迴圈鍊錶

和單向鍊錶相比,多了乙個前驅結點。如果他為空,那麼next和prior都指向自己。而對於雙迴圈鍊錶,只需要最後乙個元素的next指向head next,head next的prior指向最後乙個節點即可。新節點s插入鍊錶,s next給p結點,s prior給p prior,然後,p prior n...

迴圈鍊錶,雙向鍊錶

迴圈鍊錶 迴圈鍊錶與順序鍊錶之間的區別 迴圈鍊錶最後乙個資料的next指標域不為空,而是指向頭結點,其他基本操作大體相同,只是在判斷表結束的條件變為判斷節點的引用域是否為頭引用 雙向鍊錶 author neosong date oct 10,2017 4 43 01 pm program of in...