Singly Linked List Deletion in Middle
The steps to delete a node in the middle of the list are as follows:
- Traverse the list, searching to find if the current node's points to the next node that is the node to be deleted.
- Set that node's link to be a copy of the next nodes link.
Deletion in the middle of a Singly Linked List is O(n) as the entire list may have to be traversed.
Example:
Delete ruler from middle of list
- Traverse the List
- Is Head.link.node = ruler? -No
- Is paper.link.node = ruler? - No
- Is book.link.node = ruler? - Yes
- Set book.link = ruler.link
Ruler was deleted from the middle of the list, and this is the new layout for the Singly Linked List.