Invert a stack, without using extra data structures?
- by vks
How would you invert a stack, without using extra data structures, like a second, or temporary, stack. Thus no stack1-stack2 or stack-queue-stack implementation in the answer. You just have access to push/pop feature of a standard stack.
I think there is way to do it by keeping a global counter and using pointer manipulation. If I solve it myself, I will post it. If someone else figures it out, please post your solution.