《数据结构》实验【两栈】
来源:互联网 发布:前后端数据交互方法 编辑:程序博客网 时间:2024/05/19 18:48
#include <iostream>using namespace std;const int Max=100;template <class T>class BothStack{public:BothStack(){top1=-1;top2=Max;}~BothStack(){}void Push(int i,T x);void Pop(int i);private:T data[Max];int top1,top2;};template <class T>void BothStack<T>::Push(int i,T x){if(top1==top2-1)throw"上溢";if(i==1){data[++top1]=x;cout<<data[top1]<<endl;}if(i==2){data[--top2]=x;cout<<data[top2]<<endl;}}template <class T>void BothStack<T>::Pop(int i){if(i==1){if(top1==-1)throw"下溢";cout<<data[top1--]<<endl;}if(i==2){if(top2==Max)throw"下溢";cout<<data[top2++]<<endl;}}int main(){BothStack<int> one;cout<<"-----------top1入栈-------------"<<endl;one.Push(1,80);one.Push(1,85);cout<<"-----------top2入栈-------------"<<endl;one.Push(2,90);one.Push(2,95);cout<<"-----------top1出栈-------------"<<endl;one.Pop(1);one.Pop(1);cout<<"-----------top2出栈-------------"<<endl;one.Pop(2);one.Pop(2);return 0;}
0 0
- 《数据结构》实验【两栈】
- 《数据结构》第三章 栈和队列 实验(两栈)
- 数据结构实验之栈四:括号匹配(两种方法实现栈)
- 《数据结构》实验【顺序栈】
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三:栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三:栈和队列实验
- 数据结构:实验三 栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三:栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 《数据结构》实验三:栈和队列实验
- 《数据结构》实验三: 栈和队列实验
- 数组中的元素根据关键字筛选
- 横屏竖屏全屏
- [leetcode]Implement strStr()
- SQL Error: 17002 Cannot open connection 修改oracle数据库连接数
- vb.net(vs2010) 显示代码行号
- 《数据结构》实验【两栈】
- android框架androidannotations配置异常
- android Menu与ActionBar和TitleBar 浅析 二
- Java基本数据类型及字节
- C#读写文件
- iif(a,b,c)函数
- android 回调机制实例!
- 20、30、40,三代电信人苦辣酸甜谁能知
- ANR错误之 keyDispatchingTimedOut