当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- How many way of calling a function?
- 【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
- Zilliz 2023 Fall Campus Recruitment Officially Launched!
- MCS-51单片机,定时1分钟,汇编程序
- Live Preview | Build Business Intelligence, Quickly Embrace Financial Digital Transformation
- Canvas App中点击图标生成PDF并保存到Dataverse中
- Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
- 《数字经济全景白皮书》金融数字用户篇 重磅发布!
- "Digital Economy Panorama White Paper" Financial Digital User Chapter released!
- rosbridge-WSL2 && carla-win11
猜你喜欢
随机推荐
node连接mysql数据库报错:Client does not support authentication protocol requested by server
【day6】类与对象、封装、构造方法
The salary of soft testers at each stage, come to Kangkang, how much can you get?
LabVIEW code generation error 61056
Embedded systems: overview
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
for loop exercises
Adobe是什么?
Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!
生成器版和查看器版有什么区别?
最小化安装debian11
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
2022-08-02 mysql/stonedb slow SQL-Q18 - memory usage surge analysis
rosbridge-WSL2 && carla-win11
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
What is Adobe?
3D 语义分割——2DPASS
AOSP CameraLatencyHistogram的原理与使用
noip初赛
Scala basics [regular expressions, framework development principles]