当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
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();
}
};
如有错误,多多指教
边栏推荐
- How to write a database document management tool based on WPF (2)
- Causes of Mysql Disk Holes and Several Ways to Rebuild Tables
- Pytest learn-setup/teardown
- MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
- 一个函数有多少种调用方式?
- 冰河又一MySQL力作出版(文末送书)!!
- LabVIEW代码生成错误 61056
- Take an example of a web worker
- Scala基础【正则表达式、框架式开发原则】
- PowerMockup 4.3.4::::Crack
猜你喜欢
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
设置工作模式与环境(下):探查和收集信息
[N1CTF 2018] eating_cms
Cloud platform construction solutions
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
AOSP CameraLatencyHistogram的原理与使用
override learning (parent and child)
Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
【day6】类与对象、封装、构造方法
藏宝计划TreasureProject(TPC)系统模式开发技术原理
随机推荐
OPC UA 与IEC61499 深度融合(1)
生成器版和查看器版有什么区别?
Pytest学习-setup/teardown
Zilliz 2023 秋季校园招聘正式启动!
2022-08-03 Oracle executes slow SQL-Q17 comparison
utils 定时器
Kotlin - extension functions and operator overloading
网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)
113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself
log4j-slf4j-impl cannot be present with log4j-to-slf4j
AOSP CameraLatencyHistogram的原理与使用
【RYU】rest_router.py源码解析
一个函数有多少种调用方式?
Adobe是什么?
What is Adobe?
SPOJ 2774 Longest Common Substring(两串求公共子串 SAM)
UVa 10003 - Cutting Sticks (White Book, Interval DP)
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应
Binary search tree to solve the fallen leaves problem