Hacker News new | ask | show | jobs
by ramLlama 4993 days 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.

1 comments

That 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);
Yes and then to set it would be

  *link = (*link)->next;