当前位置:网站首页>Implementing queues with two stacks
Implementing queues with two stacks
2022-07-26 10:50:00 【Forest_ one thousand and ten】

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(); */

边栏推荐
- 2021-08-12函数递归_和鹏哥学习C语言
- @Notblank, @notnull, @notempty differences and uses
- Sql Server 数据库之数据类型
- Happens-Before原则深入解读
- 微信公众号开发 获取openid时报错40029 invalid code 问题的解决
- Flutter jni混淆 引入.so文件release包闪退
- Error[pe147]: declaration is incompatible with 'error problem
- 11 handle "self assignment" in operator=
- 349. 两个数组的交集
- Wechat official account development obtains openid times error 40029 invalid code solution
猜你喜欢
![[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]](/img/13/c6cb176d7065035f60d55ad20ed1bf.png)
[leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]

nmap弱点扫描结果可视化转换
![[leetcode daily question 2021/5/8]1723. The shortest time to complete all work](/img/e7/a48bb5b8a86cbc4cd5b37bb16661a8.png)
[leetcode daily question 2021/5/8]1723. The shortest time to complete all work

Bash shell学习笔记(一)

RT-Thread 学习笔记(五)---编辑、下载、调试程序

349. 两个数组的交集

232.用栈实现队列
![[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array](/img/9b/624416fa6a408bf64ca5438273176b.png)
[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array

在神州IV开发板上成功移植STemWin V5.22

在神州IV开发板上为STemWin 5.22加入触屏驱动
随机推荐
Bash shell学习笔记(六)
Summary of the seventh class of pengge C language
SQL Server 之Sql语句创建数据库
display-inline+calc实现左中右布局,中间自适应
鹏哥C语言20210811程序结构作业
Disable usbjatg in Altium Designer
剑指Offer(五十三):表示数值的字符串
[leetcode daily question 2021/5/8]1723. The shortest time to complete all work
104.二叉树的最大深度
242.有效的字母异位词
12 don't forget every component when copying an object
2021-08-14三子棋
Pengge C language lesson 4 (3)
Flutter集成极光推送
Pengge C language - minesweeping 2021-08-16
20210807 1 c language program structure
Bash shell学习笔记(一)
13 managing resources by objects
Sql Server之查询总结
1748.唯一元素的和