当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- The development status of cloud computing at home and abroad
- [MySQL Advanced] Creation and Management of Databases and Tables
- Conditional Statements for Shell Programming
- Unity2021发布WebGL雾效消失问题
- LabVIEW code generation error 61056
- 【bug】汇总Elipse项目中代码中文乱码解决方法!
- 物联网新零售模式,引领购物新潮流
- IELTS essay writing template
- Golang Chapter 2: Program Structure
- ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
猜你喜欢
随机推荐
.NET6之MiniAPI(十四):跨域CORS(上)
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
P1449 后缀表达式
最小化安装debian11
伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
一个函数有多少种调用方式?
SPOJ 2774 Longest Common Substring(两串求公共子串 SAM)
noip初赛
Republish the lab report
冰河又一MySQL力作出版(文末送书)!!
Deep integration of OPC UA and IEC61499 (1)
【day1】
Click the icon in Canvas App to generate PDF and save it to Dataverse
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
数据分析知识点搜集(纯粹的搜集)
P1996 约瑟夫问题
rosbridge-WSL2 && carla-win11









