当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- Boss: There are too many systems in the company, can you realize account interoperability?
- What is Adobe?
- 举一个 web worker 的例子
- [MySQL Advanced] Creation and Management of Databases and Tables
- 云平台建设解决方案
- 2022-08-03 oracle执行慢SQL-Q17对比
- Cloud platform construction solutions
- [N1CTF 2018] eating_cms
- Golang Chapter 1: Getting Started
- start with connect by implements recursive query
猜你喜欢

最小化安装debian11
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
![[N1CTF 2018] eating_cms](/img/09/3599d889d9007eb45c6eab3043f0c4.png)
[N1CTF 2018] eating_cms

ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例

3D 语义分割——2DPASS

.NET6之MiniAPI(十四):跨域CORS(上)

Embedded Systems: GPIO

【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve

生成器版和查看器版有什么区别?

rosbridge-WSL2 && carla-win11
随机推荐
Nine ways to teach you to read the file path in the resources directory
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
Binary search tree to solve the fallen leaves problem
The principle and use of AOSP CameraLatencyHistogram
2022-08-03 Oracle executes slow SQL-Q17 comparison
电商秒杀系统
noip初赛
Zilliz 2023 Fall Campus Recruitment Officially Launched!
2022-08-02 mysql/stonedb slow SQL-Q18 - memory usage surge analysis
【bug】汇总Elipse项目中代码中文乱码解决方法!
如何创建一个Web项目
What is Adobe?
rosbridge-WSL2 && carla-win11
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
.NET6之MiniAPI(十四):跨域CORS(上)
utlis 线程池
Create function report error, prompting DECLARE definition syntax problem
PowerMockup 4.3.4::::Crack
Cloud platform construction solutions