当前位置:网站首页>用栈实现队列
用栈实现队列
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();
}
};
如有错误,多多指教
边栏推荐
- 软件测试内卷严重,如何提升自己的竞争力呢?
- Nine ways to teach you to read the file path in the resources directory
- FinClip,助长智能电视更多想象空间
- [N1CTF 2018] eating_cms
- Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
- What is Adobe?
- What is the difference between the generator version and the viewer version?
- Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
- Republish the lab report
- 生成器版和查看器版有什么区别?
猜你喜欢
node连接mysql数据库报错:Client does not support authentication protocol requested by server
Pytest learn-setup/teardown
The principle and use of AOSP CameraLatencyHistogram
What is Adobe?
Embedded Systems: Clocks
Embedded systems: overview
【MySQL进阶】数据库与表的创建和管理
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
End-to-End Lane Marker Detection via Row-wise Classification
《数字经济全景白皮书》金融数字用户篇 重磅发布!
随机推荐
Boss: There are too many systems in the company, can you realize account interoperability?
PowerMockup 4.3.4::::Crack
for loop exercises
物联网新零售模式,引领购物新潮流
获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
utlis thread pool
2022-08-03 Oracle executes slow SQL-Q17 comparison
完全二叉树问题
Codeup brushing notes - simple simulation
BMN: Boundary-Matching Network for Temporal Action Proposal Generation阅读笔记
Take an example of a web worker
golang写的存储引擎,基于b+树,mmap
RPA power business automation super order!
如何创建一个Web项目
log4j-slf4j-impl cannot be present with log4j-to-slf4j
Live Preview | Build Business Intelligence, Quickly Embrace Financial Digital Transformation
MiniAPI of .NET6 (14): Cross-domain CORS (Part 1)
LabVIEW code generation error 61056
The development status of cloud computing at home and abroad
First domestic open source framework 】 【 general cloud computing framework, any program can be made into cloud computing.