用两个栈实现队列
来源:互联网 发布:ubuntu如何退出root 编辑:程序博客网 时间:2024/06/06 17:31
import java.util.Stack;public class Solution { Stack<Integer> stack1 = new Stack<Integer>(); Stack<Integer> stack2 = new Stack<Integer>(); public void push(int node) { //stack1.push(node); while (!stack1.isEmpty()) { stack2.push(stack1.pop()); } stack1.push(node); while (!stack2.isEmpty()) { stack1.push(stack2.pop()); } } public int pop() { return stack1.pop(); }// public static void main(String[] args) {// Solution solution = new Solution();// solution.push(1);// solution.push(2);// solution.push(3);// System.out.println(solution.pop());// System.out.println(solution.pop());// System.out.println(solution.pop());// }}
阅读全文
0 0
- 用两个栈实现队列 & 用两个队列实现栈
- 用两个队列实现栈&用两个栈实现队列
- 用两个栈实现队列 & 两个队列实现一个栈
- 两个栈实现队列&&用两个队列实现一个栈
- 用两个栈实现队列 & 两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- ubuntu14.04升级cmake版本后,ROS catkin_make错误解决办法
- Vue+iview报TypeError: this.$parent.updateGutter is not a function
- 面试题28—字符串的排列
- 如何看待 Kotlin 成为 Android 官方支持开发语言?
- 使用java将mysql中获得的时间戳转标准时间格式
- 用两个栈实现队列
- 小M开发_java_dya20170627
- TCP协议三次握手连接四次握手断开和DOS攻击
- RAC学习基础应用(三)--RACSubject/RACBehaviorSubject/RACReplaySubject
- Django filter中用contains 在mysql中的问题
- mac常用命令
- Android Studio插件整理
- Mongodb常用语句
- mac快捷键