![]() |
VOOZH | about |
Deleting a node in a Linked List is an important operation and can be done in three main ways: removing the first node, removing a node in the middle, or removing the last node.
In this article, we will explore deletion operation on Linked List for all the above scenarios.
Deletion at the Beginning operation involves removing the first node of the linked list.
NULL, the list is empty, and there's nothing to delete.head to the second node (head = head->next).To read more about Deletion at the Beginning Refer, Deletion at beginning (Removal of first node) in a Linked List
Deletion at a specified position in a linked list involves removing a node from a specific index/position, which can be the first, middle, or last node.
n-1 (one before the target position).next pointer: Set the next pointer of the (n-1)ᵗʰ node to point to the node after the target node (node_to_delete->next).To read more about Deletion at specific position Refer, Delete a Linked List node at a given position
Deletion at the end operation involves removing the last node of the linked list.
NULL, the list is empty, and there's nothing to delete.NULL (the list becomes empty).next of the node is the last node).next pointer of the second-last node: Set the second-last node’s next to NULL (removing the link to the last node).To read more about Deletion at the end Refer, Deletion at end (Removal of last node) in a Linked List