Algorithm for Deleting a node from the End in Doubly Linked List


Step 1: IF START = NULL 
             Write UNDERFLOW 
             Go to Step 7 
            [END OF IF] 
Step 2: SET PTR = START
Step 3: Repeat Step 4 while PTR NEXT != NULL
Step 4: SET PTR = PTR NEXT
        [END OF LOOP] 
Step 5: SET PTR PREV NEXT = NULL
Step 6: FREE PTR 
Step 7: EXIT

Explanation

  • In Step 2, we take a pointer variable PTR and initialize it with START. That is, PTR now points to the first node of the linked list.
  • The while loop traverses through the list to reach the last node.
  • Once we reach the last node, we can also access the second last node by taking its address from the PREV field of the last node.
  • To delete the last node, we simply have to set the next field of second last node to NULL, so that it now becomes the (new) last node of the linked list