对全局变量有些依赖,要改进
#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;
}