当前位置:网站首页>用栈实现队列
用栈实现队列
2022-08-03 22:55:00 【老鱼37】

思路:
class MyQueue {
stack<int>data;
stack<int>q; public: MyQueue() { } void in2() { while(!q.empty()) { data.push(q.top());
q.pop(); } } void push(int x) { q.push(x);
}
int pop() {
if(data.empty())
{
in2();
}
int x=data.top();
data.pop();
return x;
}
int peek() {
if(data.empty())
{
in2();
}
return data.top();
}
bool empty() {
return data.empty()&&q.empty();
}
};
如有错误,多多指教
边栏推荐
- 【day1】
- Take an example of a web worker
- Interpretation of ML: A case of global interpretation/local interpretation of EBC model interpretability based on titanic titanic rescued binary prediction data set using interpret
- FinClip最易用的智能电视小程序
- 最小化安装debian11
- 静态文件快速建站
- 软件测试内卷严重,如何提升自己的竞争力呢?
- Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
- Scala基础【正则表达式、框架式开发原则】
- navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
猜你喜欢

override learning (parent and child)

Walk the Maze BFS

CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应

The principle and use of AOSP CameraLatencyHistogram

Cloud platform construction solutions

win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改

BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记

PowerMockup 4.3.4::::Crack

FinClip,助长智能电视更多想象空间

noip初赛
随机推荐
Analysys Analysis: The transaction scale of China's online retail B2C market in Q2 2022 will reach 2,344.47 billion yuan
Internet user account information management regulations come into effect today: must crack down on account trading and gray products
FinClip,助长智能电视更多想象空间
Scala基础【正则表达式、框架式开发原则】
noip preliminary round
BMN: Boundary-Matching Network for Temporal Action Proposal Generation Reading Notes
redis持久化方式
雅思大作文写作模版
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
Binary search tree to solve the fallen leaves problem
HDU 5655 CA Loves Stick
What is Adobe?
Unity2021发布WebGL雾效消失问题
ML之yellowbrick:基于titanic泰坦尼克是否获救二分类预测数据集利用yellowbrick对LoR逻辑回归模型实现可解释性(阈值图)案例
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
P1449 后缀表达式
Kotlin - 扩展函数和运算符重载
"Digital Economy Panorama White Paper" Financial Digital User Chapter released!
OPC UA 与IEC61499 深度融合(1)
PowerMockup 4.3.4::::Crack