Description: You are given only a pointer to a node in a singly linked list. How do you delete this node.

 

 

If Video does not load, Click here

Algorithm:

  1. Copy Data of next node into node to be deleted
  2. Delete the next node

C implementation:-

 
/* Link list node */
struct node
{
    int data;
    struct node* next;
};
 
/* Function to delete the node */
void ( struct node *ptr)
{ struct node *t= ptr->next;
/* Copy Data of next node into node to be deleted */  
ptr->data    = t->data;
 ptr->next    = t->next;
/* Delete the next node */
   free(t);
}
Go to top