77
Deletion in doubly linked list after the specified node
In order to delete the node after the specified data, we need to perform the following steps.
- Copy the head pointer into a temporary pointer temp.
- Traverse the list until we find the desired data value.
- Check if this is the last node of the list. If it is so then we can’t perform deletion.
- Check if the node which is to be deleted, is the last node of the list, if it so then we have to make the next pointer of this node point to null so that it can be the new last node of the list.
- Otherwise, make the pointer ptr point to the node which is to be deleted. Make the next of temp point to the next of ptr. Make the previous of next node of ptr point to temp. free the ptr.
Algorithm
- Step 1: IF HEAD = NULL
- Step 2: SET TEMP = HEAD
- Step 3: Repeat Step 4 while TEMP -> DATA != ITEM
- Step 4: SET TEMP = TEMP -> NEXT
- Step 5: SET PTR = TEMP -> NEXT
- Step 6: SET TEMP -> NEXT = PTR -> NEXT
- Step 7: SET PTR -> NEXT -> PREV = TEMP
- Step 8: FREE PTR
- Step 9: EXIT
 Write UNDERFLOW
 Go to Step 9
[END OF IF]
[END OF LOOP]
C Function
Output
1.Append List 2.Delete node 3.Exit 4.Enter your choice?1 Enter the item 12 Node Inserted 1.Append List 2.Delete node 3.Exit 4.Enter your choice?1 Enter the item 23 Node Inserted 1.Append List 2.Delete node 3.Exit 4.Enter your choice?1 Enter the item 34 Node Inserted 1.Append List 2.Delete node 3.Exit 4.Enter your choice?2 Enter the value23 Node Deleted
Next TopicDoubly Linked List