设为首页 加入收藏

TOP

C语言中实现通用双链表
2014-11-23 20:29:13 】 浏览:2772
Tags:言中 实现 通用 双链表

  /**


  * C 和 C++ 的谁好谁坏的争论还在不断的继续,C语言的使用非常的广范,很多大型的系统都是用C 语言来写的。


  * C++ 似乎有更好的编程范式。支持面向对象,模版,省去了很多处理。


  * C++ 最好不要滥用,具体问题,具体分析。


  *


  */


  #include


  #include


  /**


  * 通用链表声明部分


  */


  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)


  static void __list_add(struct list_head * new, struct list_head * prev, struct list_head * next);


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


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


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


  static void list_del(struct list_head *entry);


  static void list_del_init(struct list_head *entry);


  static int list_empty(struct list_head *head);


  static void list_splice(struct list_head *list, struct list_head *head);


  #define list_entry(ptr, type, member) \


  ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member)))


  #define list_for_each(pos, head) \


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


  #define NEW_LIST_NODE(type, node) \


  {\


  node = (struct type *)malloc( sizeof(struct type)); \


  if (node == NULL) exit(-1);\


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C语言的作用域/namespace分析 下一篇原码、反码、补码,计算机中负数..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目