C语言双向循环链表
http://androidxref.com/6.0.0_r1/xref/system/core/include/cutils/list.h
struct listnode
{
struct listnode *next;
struct listnode *prev;
};
static inline void list_init(struct listnode *node) { node->next = node; node->prev = node; } static inline void list_add_tail(struct listnode *head, struct listnode *item) { item->next = head; item->prev = head->prev; head->prev->next = item; head->prev = item; } static inline void list_add_head(struct listnode *head, struct listnode *item) { item->next = head->next; item->prev = head; head->next->prev = item; head->next = item; } static inline void list_remove(struct listnode *item) { item->next->prev = item->prev; item->prev->next = item->next; }
双向循环链表
初始化: 一个节点,前向节点和后向节点都指向自己。
list_add_head 把节点加到head的后面(这里是这么实现的,没有规定说链表一定要有顺序,除非有特殊需要)
list_add_tail 在节点加到head的前面(实际上也就是循环双向链表的结尾)
不管做什么操作 head始终作为第一个节点。

浙公网安备 33010602011771号