#techlearners #java
Singly Linked List - Deletion At Position
This deletion process can be understood as follows:
To be done:
Given a ‘position’, delete the node at this position from the linked list.
How to do it:
The steps to do it are as follows:
1. Traverse the list by counting the index of the nodes
2. For each index, match the index to be same as position
3. Now, Any of the 3 conditions can be there:
• Case 1: The position is 0, i.e. the head is to be deleted
1. In this case, Change the head of the node to the next node of current head.
2. Free the memory of replaced head node.
• Case 2: The position is greater than 0 but less than the size of the list, i.e. in the middle or last, except at head
1. In this case, Find previous node of the node to be deleted.
2. Change the next of previous node to the next node of current node.
3. Free the memory of replaced node.
• Case 3: The position is greater than the size of the list, i.e. position not found in the list
1. In this case, No operation needs to be done.
TECHLEARNERS BY NEERAJ SAXENA
http://www.techlearners.co.in