日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 嵌入式 > 嵌入式軟件

1. 雙向鏈表定義:

在內核include/linux/types.h里定義了雙向鏈表結構體類型:

Struct list_head

{

Struct list_head *next,*prev;

};

2. 鏈表處理

2.1:鏈表初始化:

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name)

struct list_head name = LIST_HEAD_INIT(name)

通過LIST_HEAD(list_name)宏申明并初始化

2.2:添加元素:

2.2.1:list_add(struct list_head *new, struct list_head *head)

在現(xiàn)存的head元素之后,緊接著插入new元素

static inline void __list_add(struct list_head *new,

struct list_head *prev,

struct list_head *next)

{

next->prev = new;

new->next = next;

new->prev = prev;

prev->next = new;

}

static inline void list_add(struct list_head *new, struct list_head *head)

{

__list_add(new, head, head->next);

}

2.2.2:list_add_tail(struct list_head *new, struct list_head *head)

在現(xiàn)存數(shù)據(jù)之前添加數(shù)據(jù)

static inline void list_add_tail(struct list_head *new, struct list_head *head)

{

__list_add(new, head->prev, head);

}

2.3刪除數(shù)據(jù):

static inline void __list_del(struct list_head * prev, struct list_head * next)

{

next->prev = prev;

prev->next = next;

}

static inline void list_del(struct list_head *entry)

{

__list_del(entry->prev, entry->next);

entry->next = LIST_POISON1;

entry->prev = LIST_POISON2;

}

2.4.檢測鏈表是否為空

static inline int list_empty(const struct list_head *head)

{

return head->next == head;

}

2.5. 合并兩個鏈表

static inline void __list_splice(const struct list_head *list,

struct list_head *prev,

struct list_head *next)

{

struct list_head *first = list->next;

struct list_head *last = list->prev;

first->prev = prev;

prev->next = first;

last->next = next;

next->prev = last;

}

static inline void list_splice(const struct list_head *list,

struct list_head *head)

{

if (!list_empty(list))

__list_splice(list, head, head->next);

}

2.6:查找鏈表元素:

#define list_entry(ptr, type, member)

container_of(ptr, type, member)



本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉