3 ms·
This version is more clear for a human, but it does contain duplicate logic. This line: head = head->next; is another form of this line:
by marcell 10y ago
This version is more clear for a human, but it does contain duplicate logic.
This line:
head = head->next;
is another form of this line:
prev->next = prev->next->next;
Both delete by setting "->next". Code duplication is a common source of bugs, and that's the rationale behind Linus's version, which eliminates duped code.
- akkartik 10y agoSee my comments regarding blindly removing "duplication" at https://news.ycombinator.com/item?id=12798796 https://news.ycombinator.com/item?id=12798796 (point 4)
- alkoumpa 10y agoNot only is it duplicate, it also contains nasty "behavior". If prev->next equals NULL then dereferencing this would result in segfault, so in this case another if statement is required.