Domanda di colloquio di Amazon

implement queue with two stacks

Risposta di colloquio

Anonimo

18 mag 2012

Maintain the queue in stack1 in reversed order. If you want to retrieve the head pop the contents of stack1 into stack2, reversing it in the process. Now pop the head from stack2 and pop the rest of the items back into stack1, putting them in previous order.