当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
2022-08-03 22:55:00 【老鱼37】
class MyQueue {
public:
stack<int>in;
stack<int>out;
public:
MyQueue() {
}
void in2(){
while(!in.empty()){
out.push(in.top());
in.pop();
}
}
void push(int x) {
//入栈
in.push(x);
}
int pop() {
//出栈 就要把另一个栈全部弄过来,取栈顶
if(out.empty()){
in2();
}
int x=out.top();
out.pop();
return x;
}
int peek() {
if(out.empty())
{
in2();
}
return out.top();
}
bool empty() {
return in.empty() && out.empty();
}
};
如有错误,多多指教
边栏推荐
- .NET6之MiniAPI(十四):跨域CORS(上)
- On the Qixi Festival of 2022, I will offer 7 exquisite confession codes, and at the same time teach you to quickly change the source code for your own use
- With the rise of concepts such as metaverse and web3.0, many digital forms such as digital people and digital scenes have begun to appear.
- OPC UA 与IEC61499 深度融合(1)
- 【day1】
- BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
- utlis thread pool
- FinClip最易用的智能电视小程序
- Kotlin - 扩展函数和运算符重载
- [b01lers2020]Life on Mars
猜你喜欢
生成器版和查看器版有什么区别?
Bytebase database schema change management tool
The salary of soft testers at each stage, come to Kangkang, how much can you get?
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
Embedded systems: overview
电商秒杀系统
rosbridge-WSL2 && carla-win11
二叉搜索树解决落叶问题
complete binary tree problem
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
随机推荐
UVa 437 - The Tower of Babylon (White Book)
Kotlin - 扩展函数和运算符重载
设置工作模式与环境(下):探查和收集信息
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
utlis thread pool
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
Software testing is seriously involution, how to improve your competitiveness?
静态文件快速建站
如何创建一个Web项目
走迷宫 BFS
最小化安装debian11
complete binary tree problem
LabVIEW code generation error 61056
Codeup brushing notes - simple simulation
Embedded Systems: GPIO
Makefile
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
直播预告 | 构建业务智联,快速拥抱财务数字化转型
P1449 后缀表达式