5 ms·
When you start the list traversal, you would have something like Node** link = list_head and as you traverse, you would do link = &(entry->next) The
by ramLlama 14y ago
When you start the list traversal, you would have something like
Node** link = list_head
and as you traverse, you would do
link = &(entry->next)
Then, when you find the entry that you want to delete, link points to either (a) list_head if you are deleting the first entry or (b) the next pointer of the previous entry. Either way, doing
*link = entry->next
does the trick.
This way, you save on the conditional branch.
- deleted 14y ago[deleted]
- fr0sty 14y agoThat traversal doesn't traverse. It just skip list to entry->next and would keep resetting. You could do something like this instead: link = &((*link)->next);
- nickkthequick 14y agoYes and then to set it would be *link = (*link)->next;