Depending on the position where the new node is to be inserted, we can have the following insert operations. Insertion operation of the doubly linked list inserts a new node in the linked list. Basic Operationsįollowing are some of the operations that we can perform on a doubly linked list. We can implement a doubly linked list using a class in Java as well. A doubly linked list is represented as a class when we use STL in C++. In C-style declaration, a node of the doubly linked list is represented as follows: struct nodeĪpart from the above declaration, we can also represent a node in the doubly linked list as a class in C++. This is the main advantage of doubly linked list over the singly linked list. previous and next, we can traverse it into the directions forward and backward. Only the first node (head) has its previous node set to null and the last node (tail) has its next pointer set to null.Īs the doubly linked list contains two pointers i.e. In the above figure, we see that each node has two pointers, one pointing to the previous node and the other pointing to the next node. The next pointer of the tail node is set to NULL as this is the last node.Ī basic layout of the doubly linked list is shown in the below diagram. The previous pointer of the head is set to NULL as this is the first node.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |