c语言双循环链表,C语言--双循环链表(list_head.h)操作

#ifndef _LIST_H

#define _LIST_H

#define _INLINE_ static inline

struct list_head {

struct list_head *next, *prev;

};

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

&(name)}

#define LIST_HEAD(name) \

struct list_head name = LIST_HEAD_INIT(name)

#define INIT_LIST_HEAD(ptr) do {\

(ptr)->next = (ptr);

(ptr)->prev = (ptr); \

} while (0)

_INLINE_ void __list_add(struct list_head *add,

struct list_head *prev,

struct list_head *next)

{

next->prev = add;

add->next = next;

add->prev = prev;

prev->next = add;

}

_INLINE_ void list_add(struct list_head *add, struct list_head

*head) {

__list_add(add, head,

head->next);

}

_INLINE_ void list_add_tail(struct list_head *add, struct

list_head *head)

{

__list_add(add, head->prev,

head);

}

_INLINE_ void __list_del(struct list_head *prev, struct

list_head *next)

{

next->prev = prev;

prev->next = next;

}

_INLINE_ void list_del(struct list_head *entry)

{

__list_del(entry->prev,

entry->next);

}

_INLINE_ void list_del_init(struct list_head *entry)

{

__list_del(entry->prev,

entry->next);

INIT_LIST_HEAD(entry);

}

_INLINE_ int list_empty(struct list_head *head)

{

return head->next == head;

}

_INLINE_ void list_splice(struct list_head *list, struct

list_head *head)

{

struct list_head *first =

list->next;

if (first != list) {

struct list_head *last =

list->prev;

struct list_head *at =

head->next;

first->prev =

head;

head->next =

first;

last->next =

at;

at->prev =

last;

}

}

#define list_entry(ptr, type, member) \

((type *)((char *)(ptr) - (unsigned

long)(&((type *)0)->member)))

#define list_for_each(pos, head) \

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

(head); pos = pos->next)

#define list_for_each_safe(pos, pnext, head) \

for (pos = (head)->next, pnext =

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

pos = pnext,

pnext = pos->next)

#undef _INLINE_

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值