Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?
This is a very good interview question
The solution to this is to copy the data from the next node into this node and delete the next node!. Ofcourse this wont work if the node to be deleted is the last node. Mark it as dummy in that case. If you have a Circular linked list, then this might be all the more interesting. Try writing your own C program to solve this problem. Having a doubly linked list is always better.

Re: Given only a pointer to a node to be deleted in a singly lin
1+6 is 7
this should work too for a singly linked list
if pNode is the pointer to the node to be deleted, then, for a singly linked list,
{
temp = pNode;
pNode = pNode->next; /* load pNode with the next nodes' address */
free (temp);
}
I dont this it should work...ne comment?
i dont think, that the above method would be working because in that case you are loosing the information (pNode - 1)->next (next of previous node of pNode) which was pointing to pNode (which is gonna to delete shortly).
The original solution is perfect i guess....move the content of next node in current node and delte next node... :)
--Ashish Gupta
Hope the below concept will work.
temp=pNode; //assign to a temp
pNode=pNode->next; //move the node to next position
temp->next=PNode->next;
free(pNode);
this also won't work
In the above solution you are not deleting the node for which address is given. You are deleting the given element's next node.......