Double-linked table Application
# Ifndef list_h_defined
# Define list_h_defined
Struct list_head {
Structlist_head * next;
Structlist_head * Prev;
};
Initialization
# Define declare_list_init (name )\
Struct list_head name = {& (name), & (name )}
Static void inline list_init (structlist_head * head)
{
Head-> next = head;
Head-> Prev = head;
}
Insert a node between two nodes
Static void inline list_add (structlist_head * element, struct list_head * head)
{
Head-> next-> Prev = element;
Element-> next = head-> next;
Element-> Prev = head;
Head-> next = element;
}
Insert a linked list at the end of the linked list
Static void inline list_add_tail (structlist_head * element, struct list_head * head)
{
Head-> Prev-> next = element;
Element-> next = head;
Element-> Prev = head-> Prev;
Head-> Prev = element;
}
Delete a node
Static void inline list_del (structlist_head * _ remove)
{
_ Remove-> next-> Prev = _ remove-> Prev;
_ Remove-> Prev-> next = _ remove-> next;
# Ifdef debug
_ Remove-> next = (struct list_head *) 0xdeadb33f;
_ Remove-> Prev = (struct list_head *) 0xdeadb33f;
# Endif
}
# Define list_entry (PTR, type, member )\
(Type *) (char *) (PTR)-(unsigned long) (& (type *) 0)-> member )))
Judge whether the linked list is empty
Static inline int list_empty (const structlist_head * l)
{
Returnl-> next = L;
}
Static inline void list_splice (structlist_head * List, struct list_head * head)
{
Structlist_head * first;
Structlist_head * last;
Structlist_head * current;
First = List-> next;
Last = List-> Prev;
Current = head-> next;
First-> Prev = head;
Head-> next = first;
Last-> next = current;
Current-> Prev = last;
}
# Endif/* list_h_defined */