用两个栈实现队列
来源:互联网 发布:淘宝的钻石展位是什么 编辑:程序博客网 时间:2024/06/08 15:29
#include<iostream>#include<stack>using namespace std;template <class T> class MyQueue{stack<T> s1,s2; public: MyQueue(){} /*int size() { return s1.size()+s2.size(); } bool empty() { if(size()==0)return true;elsereturn false; }*/ void push(T value) { s1.push(value); } T pop() { if(!s2.empty()) return s2.top(); while(!s1.empty()) { s2.push(s1.top()); s1.pop(); } return s2.top(); }/* void pop() { if(s2.empty()) { while(!s1.empty()) { s2.push(s1.top()); s1.pop(); } } s2.pop(); }*/};void main(){MyQueue<char> queue;queue.push('a');queue.push('b');queue.push('c');char r = queue.pop();cout<<r<<endl;}
0 0
- 用两个栈实现队列 & 用两个队列实现栈
- 用两个队列实现栈&用两个栈实现队列
- 用两个栈实现队列 & 两个队列实现一个栈
- 两个栈实现队列&&用两个队列实现一个栈
- 用两个栈实现队列 & 两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个队列实现栈
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- 用两个栈实现队列
- android做新闻客户端用到得第三包
- scala实现设计模式之命令模式
- 用自定义缓存区的方式实现文件的移动
- 【坑】javascript中匿名函数表达式的估值操作
- 【LeetCode】之Linked List Cycle
- 用两个栈实现队列
- 动态增加文本框
- CopyOnWriteArrayList与Collections.synchronizedList的性能对比
- 《剑指Offer》面试题:数值的整数次方
- scala实现设计模式之解释器模式
- 对于内存的一点笔记
- js动态的在页面上增加或删除一个文本框
- Vysor 情怀玩法 (番外篇)--调戏妹子
- (4.2.16.4) ActivityManager