3 ms·
How would you reverse a singly linked list without traversing it? (and without knowing implementation details too I guess - doing pointer arithmetic and storing
by roel_v 16y ago
How 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.