当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- What is Adobe?
- [2022安恒夏令营] 5个小题
- Embedded Systems: Clocks
- 目标检测的国内外研究现状
- 牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
- Click the icon in Canvas App to generate PDF and save it to Dataverse
- Basic Concepts of Graphs
- UVa 1025 - A Spy in the Metro (White Book)
- 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阅读笔记
.NET6之MiniAPI(十四):跨域CORS(上)
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
Scala basics [regular expressions, framework development principles]
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
End-to-End Lane Marker Detection via Row-wise Classification
完全二叉树问题
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
Cloud platform construction solutions
随机推荐
雅思大作文写作模版
云平台建设解决方案
生成器版和查看器版有什么区别?
[2022安恒夏令营] 5个小题
伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
云计算国内外发展现状
LabVIEW代码生成错误 61056
《数字经济全景白皮书》金融数字用户篇 重磅发布!
for loop exercises
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
override学习(父类和子类)
golang写的存储引擎,基于b+树,mmap
V8中的快慢数组(附源码、图文更易理解)
utils timer
IELTS essay writing template
Golang第一章:入门
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
FinClip,助长智能电视更多想象空间
Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
Canvas App中点击图标生成PDF并保存到Dataverse中