• λ我爱Aspx >> Asp.Net >> 一个统一的链表结构
  • 一个统一的链表结构

  • :未知  Դ:internet  :2007-5-5 19:47:57  ؼ:
  • 这是在Linux下面最常用的一个统一的链表结构,Linux就是用这个结构将所有的Driver、Device什么的都分别串在一起。我觉得写得非常好,大家来看一看。

    -----------------------------------------------------------------------------------------------------

    #ifndef _LINUX_LIST_H

    #define _LINUX_LIST_H

    #ifdef __KERNEL__

    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)

    /*

    * Insert a new entry between two known consecutive entries.

    * This is only for internal list manipulation where we know the prev/next entries already!

    */

    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;

    }

    /*

    * list_add - add a new entry

    * Insert a new entry after the specified head.

    * This is good for implementing stacks.

    */

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

    {

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

    }

    /*

    * list_add_tail - add a new entry

    * Insert a new entry before the specified head.

    * This is useful for implementing queues.

    Ҷƪл˵?
  • һƪ如何写系统分析书
    һƪ优化delphi5.0秘籍大曝光