当前位置:网站首页>用栈实现队列
用栈实现队列
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();
}
};
如有错误,多多指教
边栏推荐
- 七夕活动浪漫上线,别让网络拖慢和小姐姐的开黑时间
- override学习(父类和子类)
- log4j-slf4j-impl cannot be present with log4j-to-slf4j
- 电商秒杀系统
- 二叉搜索树解决落叶问题
- First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
- 生成器版和查看器版有什么区别?
- 【MySQL进阶】数据库与表的创建和管理
- AOSP CameraLatencyHistogram的原理与使用
- 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.
猜你喜欢

"Digital Economy Panorama White Paper" Financial Digital User Chapter released!

Pytest学习-setup/teardown

ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例

Zilliz 2023 秋季校园招聘正式启动!

PowerMockup 4.3.4::::Crack

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!

HCIP BGP lab report

走迷宫 BFS

电商秒杀系统

目标检测技术研究现状及发展趋势
随机推荐
剑指offer第22题-链表中倒数第K个节点
2022-08-02 mysql/stonedb slow SQL-Q18 - memory usage surge analysis
RPA power business automation super order!
为什么我们需要回调
complete binary tree problem
Boss: There are too many systems in the company, can you realize account interoperability?
MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
Why do we need callbacks
CAS:178744-28-0,mPEG-DSPE,DSPE-mPEG,甲氧基-聚乙二醇-磷脂酰乙醇胺供应
【RYU】rest_router.py源码解析
What is Adobe?
举一个 web worker 的例子
utlis thread pool
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
【day1】
冰河又一MySQL力作出版(文末送书)!!
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
HCIP BGP lab report
UVa 437 - The Tower of Babylon(白书)