Doubly Linked List
Doubly Linked List
Doubly linked list is a complex type of linked list in which a node contains a
pointer to the previous as well as the next node in the sequence. Therefore, in a
doubly linked list, a node consists of three parts: node data, pointer to the next
node in sequence (next pointer) , pointer to the previous node (previous pointer).
A sample node in a doubly linked list is shown in the figure.
5. The Prev of the first node i.e. A and the Next of the last node i.e. D point
towards NULL.
6. This memory representation shows that the values need not be stored
contiguously.
7. The values 1000, 1056, 2004 and so on represent addresses in the memory.
1. Insertion
2. Deletion
3. Display
Insertion
In a double linked list, the insertion operation can be performed in three ways as
follows...
We can use the following steps to insert a new node at end of the double linked
list...
We can use the following steps to insert a new node after a node in the double
linked list...
Deletion
In a double linked list, the deletion operation can be performed in three ways as
follows...
We can use the following steps to delete a node from beginning of the double
linked list...
We can use the following steps to delete a node from end of the double linked
list...
We can use the following steps to delete a specific node from the double linked
list...
Every node of DLL Requires extra space for a previous pointer. It is possible
to implement DLL with a single pointer though (See this and this).
All operations require an extra pointer previous to be maintained. For
example, in insertion, we need to modify previous pointers together with the
next pointers. For example in the following functions for insertions at
different positions, we need 1 or 2 extra steps to set the previous pointer.