Doubly Linked List
Doubly Linked List
Double linked list is a sequence of elements in which every element has links to its previous
element and next element in the sequence
We can traverse forward by using the next field and can traverse backward by using the
previous field
Every node in a double linked list contains three fields
1. ‘link1’ field is used to store the address of the previous node in the sequence
2. ‘link2’ field is used to store the address of the next node in the sequence
3. ‘data’ field is used to store the actual value of that node
a) Insertion
1. At the beginning
2. At the end
3. At a specific position
b) Deletion
1. Beginning
2. End
3. Specific Position
c) Searching
To find an element in a linked list, traverse the list and compare each node’s data with the key value.
d) Traversal
a) Insertion
Insertion at the Beginning: In this operation, a new node is added at the beginning of the list,
and it becomes the new head of the list
Insertion at the End: Here, a new node is appended to the end of the list, becoming the new tail
node.
Insertion at a Specific Position: This operation involves adding a new node at a particular
position within the list, shifting the existing nodes accordingly.
Step 3: If empty, set newNode->next = NULL, newNode->prev = NULL, and head = newNode.
If temp reaches the end of the list, display "Given node not found! Insertion not possible!".
If there is only one node (temp->next == NULL), set head = NULL and delete
temp.
Else:
Delete temp.
If there is only one node, set head = NULL, delete temp1, and exit.
Otherwise:
Delete temp1.
If it is the only node, set head = NULL, delete temp1, and exit.
temp1->prev->next = temp1->next
temp1->next->prev = temp1->prev
Delete temp1
If the node is not found, display "Given node not found! Deletion not
possible!".
1. Forward Traversal:
2. Backward Traversal:
(temp = tail;
}).