The puzzle is to implement basic stack operations with using only basic queue operations. That is, a queue object is given, we need construct a wrapper for the stack functions, push, pop, which will only use the queue object as its storage, and naturally will have to use the queue operations.
This can be done using only one queue object. Although either the push or the pop complexity will no more be O(1).
Continue reading “Implement stack using a queue”
