Question d’entretien chez Amazon

implement queue with two stacks

Réponse à la question d'entretien

Utilisateur anonyme

18 mai 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.