Data Structure linked list _ Interface Definition of two-way linked list, data structure Interface Definition

Source: Internet
Author: User

Data Structure linked list _ Interface Definition of two-way linked list, data structure Interface Definition
Introduction to two-way linked list

Each element in a two-way linked list is composed of three parts: In addition to data members and next pointers, each element also contains a pointer pointing to its precursor element, called the prev pointer. The structure of a two-way linked list is as follows: link some elements together so that the next pointer of each element points to its successor element, and the prev pointer of each element points to its precursor element.

To identify the head and end of the linked list, set the prev pointer of the first element and the next pointer of the last element to NULL.

To traverse the entire two-way linked list in reverse direction, use the prev pointer to continuously access each element from the end to the header. When we know that an element is stored in a linked list somewhere, we can select the method to access it, which is very helpful. For example, a flexibility of a two-way linked list is that it provides a more intuitive way to remove an element than a single-chain table.

Bidirectional linked list Interface Definition
Dlist_init
Void dlist_init (DList * list, void (* destroy) (void * data ));
Return Value: None
Description:Initialize the two-way linked list pointed to by the list. This function must be called before the two-way linked list performs any other operation. When you call dlist_destroy, the destroy parameter provided here provides a way to release the dynamic space allocation. It works like list_destroy in a single-chain table. For a two-way linked list, if it contains data that does not need to be manually released, the destroy parameter should be set to NULL.
Complexity:O (n)







Dlist_destroy
Void dlist_destroy (DList * list );
Return Value: None
Description:Destroys the two-way linked list specified by the list parameter. You cannot perform other operations after calling this function unless you call dlist_init again. Dlist_destroy removes all elements from the linked list. If the destroy parameter passed to dlist_init is not NULL, call the function specified by destroy to recycle resources for each removed element data in the linked list.
Complexity:O (n), where n represents the number of elements in the two-way linked list.







Dlist_ins_next
Int dlist_ins_next (DList * list, DLIstElmt * element, const void * data)
Return Value: If the insert operation is successful, 1 is returned; otherwise,-1 is returned.
Description:Insert the element into the element of the two-way linked list specified by the list. When an empty linked list is inserted, the element may point to any position. To avoid confusion, the element should be set to NULL. The new element contains a pointer to data, so as long as the element is still in the linked list, the memory space referenced by data should be valid. The caller is responsible for managing the buckets referenced by data.
Complexity:O (1)







Dlist_ins_prev
Int dlist_ins_prev (DList * list, DLIstElmt * element, const void * data)
Return Value: None
Description:Insert an element before the element of the two-way linked list specified by the list. When an empty linked list is inserted, the element may point to any position. To avoid confusion, the element should be set to NULL. The new element contains a pointer to data, so as long as the element is still in the linked list, the memory space referenced by data should be valid. The caller is responsible for managing the buckets referenced by data.
Complexity:O (1)







Dlist_remove
Int dlist_remove (DList * list, DLIstElmt * element, const void * data)
Return Value: If the removal is successful, 0 is returned; otherwise,-1 is returned.
Description:Removes the element specified by the element from the list-specified two-way linked list. After the function is returned, the parameter data points to the data domain stored in the removed element. The caller is responsible for managing the buckets referenced by data.
Complexity:O (1)







Dlist_size
IntDlist_size(DList * list)
Return Value: Number of elements in the linked list.
Description:This is a macro used to calculate the number of elements in the two-way linked list specified by list.
Complexity:O (1)







Dlist_head
DListElmt *Dlist_head(Const DList * list)
Return Value: Return the Header element of the linked list.
Description:This is a macro used to return the Header element in the two-way linked list specified by the list.
Complexity:O (1)







Dlist_tail
DListElmt *Dlist_tail(Const DList * list)
Return Value: Returns the ending element of the linked list.
Description:This is a macro used to return the tail element in the two-way linked list specified by the list.
Complexity:O (1)







Dlist_is_head
Int *Dlist_is_head(Const DListElmt * element)
Return Value: If the element specified by the element parameter is a linked list Header element, 1 is returned; otherwise, 0 is returned.
Description:This is a macro used to determine whether the element specified by the parameter element is a linked list Header element.
Complexity:O (1)







Dlist_is_tail
Int *Dlist_is_tail(Const DListElmt * element)
Return Value: If the element specified by the element parameter is the end element of the linked list, 0 is returned; otherwise,-1 is returned.
Description:This is a macro used to determine whether the element specified by the parameter element is the end element of the linked list.
Complexity:O (1)







Dlist_data
Int *Dlist_data(Const DListElmt * element)
Return Value: Return the data field of the linked list element specified by the element.
Description:This is a macro used to return the data fields of the elements specified by the two-way linked list.
Complexity:O (1)







Dlist_next
DListElmt *Dlist_next(Const DListElmt * element)
Return Value: Returns the next element of the element specified by the element.
Description:This is a macro used to return the successor element of the linked list element specified by the element.
Complexity:O (1)







Dlist_prev
DListElmt *Dlist_prev(Const DListElmt * element)
Return Value: Returns the precursor element of the element specified by the element.
Description:This is a macro used to return the precursor element of the linked list element specified by the element.
Complexity:O (1)
 

 

Related Article

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.