Does this implementation of node delete works, or it my fail ?
void remove_node(node *p)
{
node **i = &node_list;
for (;(*i) != NULL && ((*i) != p); *i = ((*i)->next)) ;
if (*i != NULL)
{
(*i) = (*i)->next;
}
if (p != NULL)
{
free(p);
}
}
BTW, as far as I know, in every algorithm I saw that deletes a node from a list,
there was a variable that was supposed to keep the previous pointer. this implementation lacks this…
Assuming the
parameter p as pArgAfter for loop :-
After first if:-
After second if:-
You deleted the node pointed by pArg and not the pArg itself.
Make a little change:-