Fivestars Interview Question

Implement a queue with two stacks (enqueue, dequeue, peek)

Interview Answer

Anonymous

Sep 9, 2016

To enqueue, pop all of stack B onto onto stack A, push onto stack A. To dequeue, pop all of stack A onto stack B, then pop stack B. To peek, pop all of stack A onto stack B, then peek stack B.