Singly Linked List Deletion at End
The steps to delete a node at the end of the list are as follows:
- Traverse the list, searching to find if the current node's points to the next node that has its link set to null.
- Set that node's link to now be null.
Deletion at the end of a Singly Linked List is O(n) as the entire list had to be traversed.
Example:
Delete ruler from end of list
- Traverse the List
- Is Head.link.link = Null? -No
- Is paper.link.link = Null? - No
- Is book.link.link = Null? - No
- Is pen.link.link = Null? - Yes
- Set pen.link = Null
Ruler was deleted from the end of the list, and this is the new layout for the Singly Linked List.