Thursday, December 27, 2007
Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
Posted by Admin at 12:35 PM
Labels: Linked Lists
Subscribe to:
Post Comments (Atom)
More content will be added soon , if you have any different or better solution then please post in the comment section of the respective question.
Posted by Admin at 12:35 PM
Labels: Linked Lists
1 comments:
copy the data from the next node to the current node and delete next node.
but fails if the current node itself is the last node ofthe list.
if(node->next)
{
//copy the data
node->value=node->next->value;
// delete the node.
temp=node->next;
node->next=temp->next;
free(temp);
}
else
{
printf("cant delete already at the last node");
}
Post a Comment