当前位置:网站首页>用栈实现队列
用栈实现队列
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();
}
};
如有错误,多多指教
边栏推荐
猜你喜欢

【MySQL进阶】数据库与表的创建和管理

软测人每个阶段的薪资待遇,快来康康你能拿多少?

The salary of soft testers at each stage, come to Kangkang, how much can you get?

Canvas App中点击图标生成PDF并保存到Dataverse中

113. Teach a Man how to fish - How to query the documentation and technical implementation details of any SAP UI5 control property by yourself

pikachu Over permission

代码随想录笔记_动态规划_416分割等和子集

Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting

藏宝计划TreasureProject(TPC)系统模式开发技术原理

SPOJ 2774 Longest Common Substring(两串求公共子串 SAM)
随机推荐
Recognized by International Authorities | Yunzhuang Technology was selected in "RPA Global Market Pattern Report, Q3 2022"
《数字经济全景白皮书》金融数字用户篇 重磅发布!
亿流量大考(2):开发一套高容错分布式系统
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
Bytebase database schema change management tool
Canvas App中点击图标生成PDF并保存到Dataverse中
Lift, Splat, Shoot: Encoding Images from Arbitrary Camera Rigs by Implicitly Unprojecting to 3D 论文笔记
Scala基础【正则表达式、框架式开发原则】
云计算国内外发展现状
HDU 5655 CA Loves Stick
Golang Chapter 2: Program Structure
HCIP BGP lab report
软件测试内卷严重,如何提升自己的竞争力呢?
Embedded Systems: GPIO
How to write a database document management tool based on WPF (2)
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
目标检测技术研究现状及发展趋势
UVa 1025 - A Spy in the Metro (White Book)
目标检测的国内外研究现状