当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- What is memoization and what is it good for?
- Makefile
- rosbridge-WSL2 && carla-win11
- 网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)
- 直播预告 | 构建业务智联,快速拥抱财务数字化转型
- utlis thread pool
- 冰河又一MySQL力作出版(文末送书)!!
- Software testing is seriously involution, how to improve your competitiveness?
- UVa 437 - The Tower of Babylon (White Book)
- BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
猜你喜欢

LabVIEW code generation error 61056
Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
![[b01lers2020]Life on Mars](/img/d0/d5c9b7224542c8843ce29adc7ef713.png)
[b01lers2020]Life on Mars

Click the icon in Canvas App to generate PDF and save it to Dataverse

LabVIEW代码生成错误 61056

Pytest学习-setup/teardown

Quickly build a website with static files

Adobe是什么?

电商秒杀系统

易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
随机推荐
[2022强网杯] polydiv和gamemaster
Another MySQL masterpiece published by Glacier (send the book at the end of the article)!!
【day1】
【MySQL进阶】数据库与表的创建和管理
Adobe是什么?
Pytest学习-setup/teardown
Scala basics [regular expressions, framework development principles]
The salary of soft testers at each stage, come to Kangkang, how much can you get?
Bytebase database schema change management tool
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.
start with connect by implements recursive query
Live Preview | Build Business Intelligence, Quickly Embrace Financial Digital Transformation
创建函数报错,提示DECLARE定义语法问题
UVa 1025 - A Spy in the Metro (White Book)
utils timer
Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
Why do we need callbacks
Deep integration of OPC UA and IEC61499 (1)
七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
RPA助力商超订单自动化!