当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- AOSP CameraLatencyHistogram的原理与使用
- 易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
- What is the difference between the generator version and the viewer version?
- Summary bug 】 【 Elipse garbled solution project code in Chinese!
- Redis persistence method
- Internet user account information management regulations come into effect today: must crack down on account trading and gray products
- 藏宝计划TreasureProject(TPC)系统模式开发技术原理
- V8中的快慢数组(附源码、图文更易理解)
- OPC UA 与IEC61499 深度融合(1)
- Why do we need callbacks
猜你喜欢
随机推荐
With 4 years of work experience, the 5 communication methods between multi-threads can't be said, can you believe it?
Canvas App中点击图标生成PDF并保存到Dataverse中
Cloud platform construction solutions
LabVIEW代码生成错误 61056
What is the difference between the generator version and the viewer version?
Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
静态文件快速建站
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
RPA power business automation super order!
Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!
为什么我们需要回调
PowerMockup 4.3.4::::Crack
Why do we need callbacks
Zilliz 2023 Fall Campus Recruitment Officially Launched!
【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
MCS-51单片机,定时1分钟,汇编程序
Pytest学习-setup/teardown
【MySQL进阶】数据库与表的创建和管理
UVa 437 - The Tower of Babylon(白书)
3D 语义分割——2DPASS