![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构-栈/队列
Light丶Long
真正的大师永远都怀有一颗学徒的心
展开
-
用栈实现队列
题目: 使用栈实现队列的下列操作: push(x) -- 将一个元素放入队列的尾部。 pop() -- 从队列首部移除元素。 peek() -- 返回队列首部的元素。 empty() -- 返回队列是否为空。 示例: MyQueue queue = new MyQueue(); queue.push(1); queue.push(2); queue.peek(); // 返回...原创 2019-04-27 10:02:14 · 103 阅读 · 0 评论 -
用两个栈来实现一个队列
题目描述: 用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型 代码实现: import java.util.Stack; public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2...原创 2019-07-22 20:37:49 · 92 阅读 · 0 评论