题目描述
用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
思路
use two stack to realize a queue, which is equal to realize “first in first out”.
We need to realize the funcion of push and pop:
step1: the push of queue: just push into stack 1.
step2: the pop of the queue:
1.if there is element in stack 2, pop it.
2.if not, pop all element in stack2 and then pop.
代码
1 |
public class QueueWithTwoStack { |
近期评论