queue 模拟 stack
来源:互联网 发布:内存兼容性测试软件 编辑:程序博客网 时间:2024/05/22 11:44
class Stack {public: // Push element x onto stack. queue<int>A; queue<int>B; void push(int x) { A.push(x); } // Removes the element on top of the stack. void pop() { while(B.size()){ B.pop(); } int ans; while(A.size()){ int t=A.front(); A.pop(); if(A.size()){ B.push(t); } } while(B.size()){ A.push(B.front()); B.pop(); } } // Get the top element. int top() { while(B.size()){ B.pop(); } int ans; while(A.size()){ int t=A.front(); A.pop(); if(!A.size()) ans=t; B.push(t); } while(B.size()){ A.push(B.front()); B.pop(); } return ans; } // Return whether the stack is empty. bool empty() { return A.size()==0; }};
0 0
- stack 模拟 queue
- queue 模拟 stack
- 模拟实现 stack和queue
- 模板模拟实现stack和queue
- 【数据结构】Stack和Queue的模拟实现
- 模拟实现容器适配器 stack queue
- stack,queue
- Queue\Stack
- queue stack
- Stack&Queue
- stack&queue
- stack/queue
- Stack && Queue
- ZOJ 3210 A Stack or A Queue?【模拟】
- STL库中的stack和queue及其模拟实现
- LeetCode[Stack]----Min Stack&Stack&Queue
- Java - Queue Stack
- Queue和Stack
- JFinal框架入门
- 关于target is null for setProperty的问题总结
- live和on的区别
- 使用Jenkins搭建iOS/Android持续集成打包平台
- PreferenceFragment 和 PreferenceActivity讲解
- queue 模拟 stack
- struts.xml的常用配置
- 模型变高问题测试及原因
- E-R图
- 【低功耗架构开发系列】(二)不找SVN托管代码了,直接用Visual Studio Online
- Spring Boot MyBatis 连接数据库
- Java 判断点是否在特定区域内
- Pro Android学习笔记(一五五):传感器(5): 磁场传感器和方位(上)
- Hibernate工作原理及为什么要用?