3 ms·
This almost works, but the caller will not know when foobar() has deleted the list head, and you update prev_link to the current_node even if you have deleted t
by tveita 14y ago
This almost works, but the caller will not know when foobar() has deleted the list head, and you update prev_link to the current_node even if you have deleted that node
Did you mean:
void foobar(Node **prev_link)
{
Node *current_node;
while((current_node = *prev_link) != NULL) {
/* ...do something... */
if (must_remove(current_node)) {
*prev_link = current_node->next;
free(current_node);
} else {
prev_link = &(current_node->next);
}
}
}
- graue 14y agoThere you go. So for future reference, if anyone wonders how many HN commenters it takes to iterate over a linked list correctly? The answer is four. :P