The implementation of the traditional interview question about in-place reversing of the single-linked list.
Details
Details
Diff Detail
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
sys/sys/queue.h | ||
---|---|---|
567 | Rather than forcing consumers to declare these variable, it'd be better IMO to pass the type name as parameter, and declare temp variables within the macro. This is consistent with how the *_SWAP macros work. |
Comment Actions
I've also written a corresponding test, to be uploaded to a new revision.
sys/sys/queue.h | ||
---|---|---|
567–579 | (head)->stqh_last = &STAILQ_FIRST(head); is wrong. I'm also suggesting to break early if the stailq is empty, as this seems clearer and it alleviates the need to introduce a similar test when setting ->stqh_last. |
Comment Actions
I'd also suggest removing _Var = STAILQ_LAST(head, type, field); and setting ->stqh_first to _Varp directly, as _Varp already contains the old last/new first element.