Algorithm for Deleting a node from the Beginning in Doubly Linked List
Step 1: IF START = NULL
Go to Step 6
[END OF IF]
Step 2: SET PTR = START
Step 3: SET START = START NEXT
Step 4: SET START PREV = NULL
Step 5: FREE PTR
Step 6: EXIT
- In Step 1 of the algorithm, we check if the linked list exists or not. If START = NULL, then it signifies that there are no nodes in the list and the control is transferred to the last statement of the algorithm.
- However, if there are nodes in the linked list, then we use a temporary pointer variable PTR that is set to point to the first node of the list.
- For this, we initialize PTR with START that stores the address of the first node of the list.
- In Step 3, START is made to point to the next node in sequence and finally the memory occupied by PTR (initially the first node of the list) is freed and returned to the free pool.