Data structure of double linked list
What is the Doubly Linked List?
The Doubly Linked List is a variant of the Linked List, in which browsing through the buttons can be done in two ways: easy forward and backward. when compared with Single Link List. Here are some important concepts to keep in mind about the Double Link List.
Link : each link of a linked List can store a data and is called an element.
Next : each link of a linked list can contain a link to the next link and is called Next.
Prev : each link of a linked list may contain a link to previous links and is called Prev.
First and Last : a List of links containing links that link to the first link called First and to the last link called Last.
Performing List of double links
As shown above, you need to remember:
The list of double links contains a link element and is called First and Last.
Each link has a data field and a link field called Next.
Each link is linked to the next element by using Next Link.
Each link is linked to the previous element by using Prev Link.
Last Link brings a link pointing to NULL to mark the end of the Link List.
Basic activities on the Double Link List
Insert operation : add an element to the top position of the Linked List.
Delete operation : delete an element at the beginning of the Linked List.
Inserting operation at the end : add an element to the end position of the Linked List.
Activity to delete the last element: delete an element at the end of the Linked List.
The following insert operation : add an element after an element of the Linked List.
Delete operation (by key) : Delete an element from the Linked List by using the provided key.
Display the list forward : display the entire Link list in the forward direction.
Display the list to the back : display the entire Link list in the backward direction.
Insert operation in the double linked list
The following is an algorithm that illustrates the insert operation at the beginning of a double linked list.
//Chèn link tại vị trí đầu tiên void insertFirst ( int key , int data ) { //tạo một link struct node * link = ( struct node *) malloc ( sizeof ( struct node )); link -> key = key ; link -> data = data ; if ( isEmpty ()) { //Biến nó thành last link last = link ; } else { //Cập nhật prev link đầu tiên head -> prev = link ; } //Trỏ nó tới first link cũ link -> next = head ; //Trỏ first tới first link mới head = link ; }
To find out the detailed code of the double linked list in C language, please click on the chapter: Program of double link list in C.
According to Tutorialspoint
Previous article: Linked list data structure (Linked List)
Next article: Loop List List (Circular Linked List)
You should read it
- How to Wire a Double Switch
- Linked list data structure (Linked List)
- Instructions for creating double exposure images in Photoshop
- How to Double Space
- Steps to fix double quotes in Word
- The To-do List is good, the Done List is very good, but the Do-Not-Do List is much better
- How to Print Double Quotes in Java
- How to check the link security embedded in the email
May be interested
- Data Link List structure (Circular Linked List)the linked list (circular linked list) is a variant of the linked list, in which the first element points to the last element and the last element points to the first element.
- Stack data structure (Stack)a stack is an abstract data structure (abstract data type - adt for short), mostly used in almost every programming language. name the stack because it acts as a stack in real life, such as a deck of cards or a stack of disks ...
- Queue data structure (Queue)queue (queue) is an abstract data structure, is something similar to queues in everyday life (queuing).
- Linear search algorithm (Linear Search)linear search is a very basic search algorithm. in this type of search, a continuous search operation takes place through every element. each element is checked and if any connection is found, that particular element is returned; if not found, the search process continues until the data is searched.
- Binary Search algorithm (Binary Search)binany search is a fast search algorithm with runtime complexity of Ο (log n). the algorithm of binary search works based on the principle of division and rule (divide and conquer). in order for this algorithm to work correctly, the data set should be in sorted form.
- Interpolation Search algorithm (Interpolation Search)interpolation search (interpolation search) is an improved variant of binary search (binary search). in order for this search algorithm to work correctly, the data set must be sorted.