3 ms·
If you have to traverse a linked list at any time to reverse it, you're doing it wrong.
by habitue 16y ago
If you have to traverse a linked list at any time to reverse it, you're doing it wrong.
- roel_v 16y agoHow would you reverse a singly linked list without traversing it? (and without knowing implementation details too I guess - doing pointer arithmetic and storing the size somewhere else doesn't count).
- mjw 16y agoI think he means: if you have to traverse it without building up a result (or doing some in-place modification) as you go - then you're doing it wrong. Obviously you gotta traverse the thing at least once.
- ydant 16y agoIf that's what he meant, his comment was pretty much useless. Anyway, I misread "traverse" for "reverse", hence my incredulous comment. Perhaps traverse means different things to the two of us.