当前位置:网站首页>用栈实现队列
用栈实现队列
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();
}
};
如有错误,多多指教
边栏推荐
- 最小化安装debian11
- Cloud platform construction solutions
- navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
- redis持久化方式
- 【论文阅读】TRO 2021: Fail-Safe Motion Planning for Online Verification of Autonomous Vehicles Using Conve
- Create function report error, prompting DECLARE definition syntax problem
- 伴随着元宇宙、web3.0等概念的兴起,数字人、数字场景等诸多数字化的形态开始出现
- 获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
- HDU 5655 CA Loves Stick
- 关于IDO预售系统开发技术讲解丨浅谈IDO预售合约系统开发原理分析
猜你喜欢
LabVIEW code generation error 61056
2022-08-03 Oracle executes slow SQL-Q17 comparison
MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
PowerMockup 4.3.4::::Crack
物联网新零售模式,引领购物新潮流
Binary search tree to solve the fallen leaves problem
Embedded systems: overview
Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
ML's yellowbrick: A case of interpretability (threshold map) for LoR logistic regression model using yellowbrick based on whether Titanic was rescued or not based on the two-class prediction dataset
随机推荐
websocket多线程发送消息报错TEXT_PARTIAL_WRITING--自旋锁替换synchronized独占锁的使用案例
Redis persistence method
生成器版和查看器版有什么区别?
utils 定时器
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
电商秒杀系统
2022-08-03 oracle执行慢SQL-Q17对比
Kotlin - extension functions and operator overloading
Take an example of a web worker
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
Codeup刷题笔记-简单模拟
What is Adobe?
What is the difference between the generator version and the viewer version?
走迷宫 BFS
Republish the lab report
静态文件快速建站
override学习(父类和子类)
如何创建一个Web项目
软测人每个阶段的薪资待遇,快来康康你能拿多少?