Algorithm for deleting a node from the End in circular linked list


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

Explanation

  • We take a pointer variable PTR and initialize it with START. That is, PTR now points to the first node of the linked list.
  • In the while loop, we take another pointer variable PREPTR such that PREPTR always points to one node before PTR.
  • Once we reach the last node and the second last node, we set the next pointer of the second last node to START, so that it now becomes the (new) last node of the linked list.