当前位置:网站首页>用两个栈实现队列
用两个栈实现队列
2022-07-26 10:42:00 【Forest_1010】

class CQueue {
public:
stack<int>InStack;
stack<int>OutStack;
CQueue() {
}
void appendTail(int value) {
InStack.push(value);
}
int deleteHead() {
if(InStack.empty())
return -1;
if(OutStack.empty())
{
while(!InStack.empty())
{
OutStack.push(InStack.top());
InStack.pop();
}
}
int result=OutStack.top();
OutStack.pop();
while(!OutStack.empty())
{
InStack.push(OutStack.top());
OutStack.pop();
}
return result;
}
};
/** * Your CQueue object will be instantiated and called as such: * CQueue* obj = new CQueue(); * obj->appendTail(value); * int param_2 = obj->deleteHead(); */

边栏推荐
- RT thread learning notes (III) -- building a compilation environment with scons
- 英语基础句型结构------起源
- 第6期:大学生应该选择哪种主流编程语言
- Flutter报错 Incorrect use of ParentDataWidget When the exception was thrown, this was the stack:
- 使用float实现左中右布局,中间内容自适应
- Error[Pe147]: declaration is incompatible with '错误问题
- Codepoint 58880 not found in font, aborting. flutter build apk时报错
- 文案秘籍七步曲至----文献团队协作管理
- Sql Server 数据库之初学体验
- Constructors, method overloads, object arrays, and static
猜你喜欢

.net5wtm (asp.net core) PgSQL unpacking operation

Sql Server 数据库之数据类型
![[leetcode daily question 2021/2/14]765. Lovers hold hands](/img/be/8639a05c733638bf0b3fdeb11abccf.png)
[leetcode daily question 2021/2/14]765. Lovers hold hands

RT-Thread 学习笔记(一)---配置RT-Thread开发环境

Problems encountered in QRcode QR code (C language)

文案秘籍七步曲至----文献团队协作管理

Issue 5: the second essential skill for College Students

Issue 8: cloud native -- how should college students learn in the workplace
![[leetcode daily question 2021/4/23]368. Maximum divisible subset](/img/0b/32ca862963c842a93f79eaac94fb98.png)
[leetcode daily question 2021/4/23]368. Maximum divisible subset

Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL
随机推荐
[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]
Flutter编译报错 version of NDK matched the requested version 21.0.6113669. Versions available locally: 2
2021-08-12函数递归_和鹏哥学习C语言
Add touch screen driver for stemwin 5.22 on Shenzhou IV development board
[paper after dinner] deep mining external perfect data for chestx ray disease screening
.net operation redis set unordered collection
2021-08-14三子棋
Constructors, method overloads, object arrays, and static
MySQL速学笔记-2021-08-31
Pengge C language lesson 4 (3)
el-table实现可编辑表格
The problem of large fluctuation of hx711 data
RT thread learning notes (I) -- configure RT thread development environment
PLC与伺服电机连接
SAP ABAP 守护进程的实现方式
MFC多线程的简单使用
Sql Server之查询总结
Issue 6: which mainstream programming language should college students choose
sigmod 函数与softmax 函数对比
winpcap 抓包函数pcap_loop(),停止问题