232. Implement Queue using Stacks

Implement the following operations of a queue using stacks.
push(x) -- Push element x to the back of queue.
pop() -- Removes the element from in front of queue.
peek() -- Get the front element.
empty() -- Return whether the queue is empty.

只在push方法里倒腾一下数据, 原理相似于用队列实现栈!

232. Implement Queue using Stacks_第1张图片

你可能感兴趣的:(232. Implement Queue using Stacks)