Double-linked table Application

Source: Internet
Author: User

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 */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.