两个栈实现一个顺序栈
来源:互联网 发布:电影照片是什么软件 编辑:程序博客网 时间:2024/06/11 10:17
#include <iostream>
#include <stack>
usingnamespacestd;
class STACK{
public:
void Push(int val)
{stack<int> temp;
temp.push(val);
while (st.empty() == false)
{if (st.top() > temp.top())
{while (st.empty() == false)
{ temp.push(st.top());
st.pop();
}
}
else
{
int num = temp.top();
temp.pop();
temp.push(st.top());
st.pop();
temp.push(num);
} }
while (temp.empty() == false)
{ st.push(temp.top());
temp.pop();
} }void Pop()
{ st.pop(); }int Top()
{return st.top();
}void Printf()
{stack<int> temp = st;
while (temp.empty() == false)
{
cout << temp.top()<<" "; temp.pop(); } cout << endl; }private:stack<int> st;};int main(){ STACK st; st.Push(5); st.Push(1); st.Push(6); st.Push(0); st.Push(9); st.Push(3); st.Printf(); return0;}
- 两个栈实现一个顺序栈
- 两个顺序栈实现顺序队列功能
- 2.用两个顺序存储结构的栈实现一个队列
- 两个队列实现一个栈&两个栈实现一个队列
- 两个栈实现一个队列-----两个队列实现一个栈
- 两个栈实现一个队列&&两个队列实现一个栈
- 两个栈实现一个队列 && 两个队列实现一个栈
- 两个栈实现一个队列,两个队列实现一个栈
- 两个栈实现一个队列/两个队列实现一个栈
- 两个栈实现一个队列&两个队列实现一个栈
- 两个队列实现一个栈&两个栈实现一个队列
- 两个队列实现一个栈 / 两个栈实现一个队列
- 两个栈实现一个队列,两个队列实现一个栈
- 两个栈实现一个队列&两个队列实现一个栈
- 两个栈实现一个队列&&两个队列实现一个栈
- 两个栈实现一个队列&两个队列实现一个栈
- 两个栈实现一个队列/两个队列实现一个栈
- 两个栈实现一个队列
- 月光族的最佳财务规划
- Swing下的二维随机游走轨道模拟
- 线程池原理(讲的非常棒)
- 线段覆盖
- caffe windwos安装测试相关问题
- 两个栈实现一个顺序栈
- [51MCU] Chapter1:概述
- 安卓开发的监听事件
- 转载:读懂C/C++递归
- 再来说说linux中重要的alias命令------从findcpp命令说起
- auto_ptr,weak_ptr个人理解
- 关于git冲突报错-> Line XX: StartTag: invalid element name
- usaco月赛MOOCRYPT
- 黑马程序员——C语言学习笔记02 控制语句:分支、跳转、循环和函数一些需要注意的问题