Delete node in linked list without head pointer and traversing

Delete node in linked list without head pointer and traversing

Problem – You have given only pointer to a particular node to delete that node without using head node and traversing

Solution – There is no practical solution possible to delete node directly by given pointer, but there is a way to delete that node logically rather than physically in memory. And the solution is to copy the data from the next node to the current node by given pointer to be deleted and delete the next node. Something like following example

Note: This solution doesn’t work if the node to be deleted is the last node of the list.

 

Output

Delete node in linked list without head pointer and traversing

Suggested Reading

  1. Write a program to reverse a linked list using stack in c++
  2. Write a c program to implement a queue using array and linked list
  3. Write a c program to implement a stack using an array and linked list