《剑指》7
来源:互联网 发布:php 用户登录次数 编辑:程序博客网 时间:2024/05/16 09:22
题目:用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
package offer;import java.util.Stack;/** * 用两个栈来实现一个队列,完成队列的Push和Pop操作。 * 队列中的元素为int类型。 * @author WQC * */public class offer7_TwoStackImplQueue { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); public void push(int node) { stack1.push(node); } public int pop() { if(stack2.isEmpty()){ if(stack1.isEmpty()){ return -1; } while(!stack1.isEmpty()){ stack2.push(stack1.pop()); } } return stack2.pop(); }}
0 0
- 《剑指》7
- 剑指Offer-7
- 剑指offer面试题7
- 剑指offer 面试题7
- 剑指offer-面试题7
- 剑指offer[7]跳台阶
- 【面试题】剑指offer 7
- SAP推出Business Suite 7 剑指SaaS
- 剑指offer(7)-反转一个链表
- 剑指Offer(面试题6~7)
- 剑指Offer面试题7 & Leetcode232
- 剑指Offer学习 面试题7
- 剑指Offer-7:重建二叉树
- 剑指offer-->面试题7 用两个栈实现队列
- 剑指offer第7题 两个栈实现队列
- 剑指offer:7-用两个栈实现队列
- 【剑指offer】面试题7:两个栈实现队列
- 【剑指offer】面试题7:用两个栈实现队列
- 最小生成树
- poj2688
- PHP程序的开始与结束
- 【图像处理与医学图像处理】NV12与YV12的区别
- session入库
- 《剑指》7
- Intellij IDEA调试区工具的使用方法
- 快包之个人见解
- 程序功能:建立一个带有头结点的单向链表,并将存储在数组中的字符依次转储到链表的各个结点中。
- [NOIP模拟][状压dp][dfs序列][线段树]
- 动态绑定和静态绑定(虚函数)
- LeetCode No.173 Binary Search Tree Iterator
- windows进入安全模式
- datastage使用中datetime型字段的transformer