题意:

  用队列来实现栈。

思路:

  没有什么捷径,纯粹模拟。但是用一个队列就够了。

 class Stack {
/*
// Push element x onto stack.
void push(int x) { } // Removes the element on top of the stack.
void pop() { } // Get the top element.
int top() { } // Return whether the stack is empty.
bool empty() { }
*/
queue<int> que;
public:
void push(int x)
{
que.push(x);
}
void pop(void)
{
if(!que.empty())
{
int n=que.size(),pos=;
while(pos<n)
{
que.push(que.front());
que.pop();
pos++;
}
que.pop();
}
}
int top()
{
if(!que.empty())
{
int n=que.size(), pos=,x=;
while(pos<=n)
{
if(pos==n) x=que.front();
que.push(que.front());
que.pop();
pos++;
}
return x;
}
}
bool empty(void)
{
if(que.empty()) return true;
else return false;
}
};

AC代码

最新文章

  1. Chp11 11.7
  2. 修复 XE8 for Android 分享图片到 Gmail 权限不足的问题
  3. 重新想象 Windows 8.1 Store Apps (92) - 其他新特性: CoreDispatcher, 日历, 自定义锁屏系列图片
  4. 设置presentVC跟PushVC一样的效果即从右到左的动画
  5. [译]Cassandra的数据读写与压缩
  6. AIX topas命令详解
  7. C#结构内存布局介绍
  8. svn笔记2
  9. C# .Net 使用zxing.dll生成二维码,条形码
  10. iOS8 UISearchViewController搜索功能讲解
  11. JavaScript模块化 --- Commonjs、AMD、CMD、es6 modules
  12. The authenticity of host &#39;github.com (192.30.253.113)&#39; can&#39;t be established.
  13. C# Winform无边框窗口拖动
  14. 痞子衡嵌入式:飞思卡尔Kinetis开发板OpenSDA调试器那些事(上)- 背景与架构
  15. echarts柱状图点击阴影部分触发事件
  16. Windows上安装 TensorFlow及简单命令
  17. AMH 软件目录介绍
  18. linux eclipse 报错过时的方法
  19. 我的第一个HTML5应用
  20. bootstrap 多级下拉菜单

热门文章

  1. com组件接口
  2. webapi方式
  3. Linux创建LVM
  4. YUM安装提示PYCURL ERROR 6 - "Couldn&#39;t错误的解决办法
  5. [Jquery]焦点图轮播效果
  6. ubuntu 14.04 安装截图工具 Shutter及使用
  7. ARM2440换lcd
  8. Visual Studio Ultimate 2013 with Update 4
  9. 访问FLASH设备-W25X16
  10. Access 中数据库操作时提示from子句语法错误