双向循环链表的应用

来源:互联网 发布:淘宝助理app 编辑:程序博客网 时间:2024/06/06 19:00
#ifndef DOUBLELINKEDLIST_H#define DOUBLELINKEDLIST_H/*1.本库文件基于双向循环链表的应用2.参考Linux内核源码的list.h文件3.详细说明查看自己总结的文档《Linux中List.h文件的分析和应用》*/#include <stdio.h>#include <malloc.h>#include <stdlib.h>struct list_head {struct list_head *next; struct list_head *prev;};#define LIST_HEAD_INIT(name) { &(name), &(name) }#define LIST_HEAD(name) \struct list_head name = LIST_HEAD_INIT(name)static inline void INIT_LIST_HEAD(struct list_head *list){list->next = list;list->prev = list;}//插入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);}//适用于队列static inline void list_add_tail(struct list_head *new, struct list_head *head){__list_add(new, head->prev, head);}#endif

0 0
原创粉丝点击