当前位置:网站首页>用两个栈模拟队列
用两个栈模拟队列
2022-08-03 22:55:00 【老鱼37】
class MyQueue {
public:
stack<int>in;
stack<int>out;
public:
MyQueue() {
}
void in2(){
while(!in.empty()){
out.push(in.top());
in.pop();
}
}
void push(int x) {
//入栈
in.push(x);
}
int pop() {
//出栈 就要把另一个栈全部弄过来,取栈顶
if(out.empty()){
in2();
}
int x=out.top();
out.pop();
return x;
}
int peek() {
if(out.empty())
{
in2();
}
return out.top();
}
bool empty() {
return in.empty() && out.empty();
}
};
如有错误,多多指教
边栏推荐
猜你喜欢
Diazo Biotin-PEG3-DBCO | Diazo Compound Modified Biotin-Tripolyethylene Glycol-Dibenzocyclooctyne
Zilliz 2023 Fall Campus Recruitment Officially Launched!
.NET6之MiniAPI(十四):跨域CORS(上)
直播预告 | 构建业务智联,快速拥抱财务数字化转型
牛客2022 暑期多校3 H Hacker(SAM + 线段树查询区间内部最大子段和)
易观分析:2022年Q2中国网络零售B2C市场交易规模达23444.7亿元
Network basic learning series four (network layer, data link layer and some other important protocols or technologies)
PowerMockup 4.3.4::::Crack
静态文件快速建站
Embedded systems: overview
随机推荐
Websocket multi-threaded sending message error TEXT_PARTIAL_WRITING--Use case of spin lock replacing synchronized exclusive lock
What is memoization and what is it good for?
【day1】
获国际权威认可 | 云扩科技入选《RPA全球市场格局报告,Q3 2022》
Republish the lab report
Code Casual Recording Notes_Dynamic Programming_416 Segmentation and Subsetting
Summary bug 】 【 Elipse garbled solution project code in Chinese!
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
Testng监听器
for loop exercises
【开源框架】国内首个通用云计算框架,任意程序都可做成云计算。
End-to-End Lane Marker Detection via Row-wise Classification
P1449 后缀表达式
Click the icon in Canvas App to generate PDF and save it to Dataverse
noip初赛
雅思大作文写作模版
静态文件快速建站
ML之interpret:基于titanic泰坦尼克是否获救二分类预测数据集利用interpret实现EBC模型可解释性之全局解释/局部解释案例
2019年10月SQL注入的两倍
Binary search tree to solve the fallen leaves problem