How to delete a node in linked list in c:
If a pointer to a node in the single linked list is provided, then how to delete that node with out traversing through that linked list?
With out traversing through the linked list, it is not possible to delete a give node, because when we are deleting that node, we have to make sure that previous node will point to the next node of current node. since we are not traversing, this is not possible.
call free(node); and assign node=NULL; so that the node will be deleted successfully.
since we have to delete node without traversing, we can copy the content of next node to current node, and delete the next node. But this trick will not work if the node supplied is the last node.
we can free the current node, and change the previous node next pointer to point to next node of current node.
Back To Top