当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
猜你喜欢

Analysys Analysis: The transaction scale of China's online retail B2C market in Q2 2022 will reach 2,344.47 billion yuan

关于IDO预售系统开发技术讲解丨浅谈IDO预售合约系统开发原理分析

代码随想录笔记_动态规划_416分割等和子集

软件测试内卷严重,如何提升自己的竞争力呢?

电商秒杀系统

重发布实验报告

软测人每个阶段的薪资待遇,快来康康你能拿多少?

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

Boss: There are too many systems in the company, can you realize account interoperability?

Fluorescein-PEG-CLS, cholesterol-polyethylene glycol-fluorescein scientific research reagent
随机推荐
2019年10月SQL注入的两倍
Click the icon in Canvas App to generate PDF and save it to Dataverse
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
Pytest学习-setup/teardown
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
[2022强网杯] polydiv和gamemaster
PowerMockup 4.3.4::::Crack
如何创建一个Web项目
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.
【开源框架】国内首个通用云计算框架,任意程序都可做成云计算。
Zilliz 2023 秋季校园招聘正式启动!
What is the difference between the generator version and the viewer version?
[b01lers2020]Life on Mars
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
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
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
The principle and use of AOSP CameraLatencyHistogram
Testng监听器