Hide Index
- Understanding insertion at beginning
- Insert at beginning
- Understanding insertion at end
- Insert at end
- Understanding insertion after the given node
- Insert after the given node
- Understanding insertion before a given node
- Insert before the given node
- Understanding insertion at a given distance
- Insert at given distance
- Understanding deletion of first node
- Delete first node
- Understanding deletion of last node
- Delete last node
- Understanding deletion by given data
- Delete node with given data
- Delete nodes with given data
- Understanding deletion after a given node
- Delete node after the given node
- Understanding deletion before a given node
- Delete node before the given node
- Understanding deletion of the given node
- Delete the given node
- Understanding deletion at a given distance
- Delete node at given distance
Understanding deletion after the given node
This case remains more or less the same as its counterpart in a singly linked list. Here, as an extra step, we also need to update the previous pointer after the deletion operation, but we have already done it for other operations, so you must be familiar with it by now. Let's examine all the cases we need to consider.
1. The list is empty
If the list is empty and contains no elements, we cannot find the given node because it does not exist within the list. Deleting the node after the given node is not possible because there is no reference point within the list to perform the deletion. In this case, we can return the existing head, as the list is empty, and no node needs to be deleted.
The list is empty
Liking the course? Check our discounted plans to continue learning.