顺序栈
来源:互联网 发布:网络词语大全及意思 编辑:程序博客网 时间:2024/05/17 04:21
对全局变量有些依赖,要改进
#include <iostream>using namespace std;typedef int elemType; //定义栈元素类型const elemType MAXSIZE = 100;int poporder = 0;class Seqstack{public: Seqstack(); ~Seqstack(); bool push(elemType x); //进栈 bool pop(); //出栈private: int top; elemType stack[MAXSIZE];};Seqstack::Seqstack(){ top = -1;}Seqstack::~Seqstack(){ top = -1;}bool Seqstack::push(elemType data){ if(top == MAXSIZE - 1) { return false; } stack[++top] = data; return true;}bool Seqstack::pop(){ int data; if(top == -1) { return false; } data = stack[top--]; arr[++poporder] = data; return true;}
0 0