当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- 静态文件快速建站
- 【RYU】rest_router.py源码解析
- 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
- 【bug】汇总Elipse项目中代码中文乱码解决方法!
- Nine ways to teach you to read the file path in the resources directory
- Another MySQL masterpiece published by Glacier (send the book at the end of the article)!!
- [2022安恒夏令营] 5个小题
- Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
- 雅思大作文写作模版
- 软测人每个阶段的薪资待遇,快来康康你能拿多少?
猜你喜欢

rosbridge-WSL2 && carla-win11

ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset

【day6】类与对象、封装、构造方法

Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂

HCIP BGP lab report

pikachu Over permission

Embedded Systems: GPIO

rosbridge-WSL2 && carla-win11

网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)

Canvas App中点击图标生成PDF并保存到Dataverse中
随机推荐
【MySQL进阶】数据库与表的创建和管理
V8中的快慢数组(附源码、图文更易理解)
The principle and use of AOSP CameraLatencyHistogram
Makefile
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
直播预告 | 构建业务智联,快速拥抱财务数字化转型
为什么我们需要回调
重发布实验报告
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应
二叉搜索树解决落叶问题
UVa 437 - The Tower of Babylon (White Book)
Optimize the query (work in progress)
Golang Chapter 1: Getting Started
Software testing is seriously involution, how to improve your competitiveness?
UVa 1025 - A Spy in the Metro (White Book)
utlis 线程池
Testng监听器
剑指offer第22题-链表中倒数第K个节点