当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- Golang Chapter 2: Program Structure
- 举一个 web worker 的例子
- 3D 语义分割——2DPASS
- Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素科研试剂
- Fluorescein-PEG-CLS, cholesterol-polyethylene glycol-fluorescein scientific research reagent
- 获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
- UVa 10003 - Cutting Sticks (White Book, Interval DP)
- encapsulation, package, access modifier, static variable
- Nine ways to teach you to read the file path in the resources directory
- 电商秒杀系统
猜你喜欢

rosbridge-WSL2 && carla-win11

Embedded Systems: Clocks

七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间

The salary of soft testers at each stage, come to Kangkang, how much can you get?

Summary bug 】 【 Elipse garbled solution project code in Chinese!

3D 语义分割——2DPASS

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

First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.

Cloud platform construction solutions

生成器版和查看器版有什么区别?
随机推荐
End-to-End Lane Marker Detection via Row-wise Classification
UVa 437 - The Tower of Babylon(白书)
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
Embedded Systems: Clocks
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
工作小计 QT打包
2022-08-02 mysql/stonedb慢SQL-Q18-内存使用暴涨分析
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
RPA power business automation super order!
complete binary tree problem
FinClip,助长智能电视更多想象空间
最小化安装debian11
CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应
完全二叉树问题
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
log4j-slf4j-impl cannot be present with log4j-to-slf4j
With the rise of concepts such as metaverse and web3.0, many digital forms such as digital people and digital scenes have begun to appear.
数据分析知识点搜集(纯粹的搜集)
2019年10月SQL注入的两倍
override learning (parent and child)