当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- Kotlin - extension functions and operator overloading
- [2022强网杯] polydiv和gamemaster
- HCIP BGP lab report
- [b01lers2020]Life on Mars
- 冰河又一MySQL力作出版(文末送书)!!
- 电商秒杀系统
- Research status of target detection at home and abroad
- End-to-End Lane Marker Detection via Row-wise Classification
- Quickly build a website with static files
- 获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
猜你喜欢

"Digital Economy Panorama White Paper" Financial Digital User Chapter released!

Embedded Systems: GPIO

noip preliminary round

Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"

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

rosbridge-WSL2 && carla-win11

PowerMockup 4.3.4::::Crack

【bug】汇总Elipse项目中代码中文乱码解决方法!

ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例

Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
随机推荐
Nine ways to teach you to read the file path in the resources directory
Pytest learn-setup/teardown
目标检测的国内外研究现状
2019年10月SQL注入的两倍
Canvas App中点击图标生成PDF并保存到Dataverse中
Zilliz 2023 秋季校园招聘正式启动!
如何创建一个Web项目
Why do we need callbacks
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
UVa 1025 - A Spy in the Metro (White Book)
Pytest学习-setup/teardown
设置工作模式与环境(下):探查和收集信息
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
Click the icon in Canvas App to generate PDF and save it to Dataverse
Republish the lab report
Software testing is seriously involution, how to improve your competitiveness?
Testng监听器
UVa 437 - The Tower of Babylon(白书)
静态文件快速建站