#include <iostream>
#define Max 100
using namespace std;
typedef int status;
typedef int selemtype;
typedef struct
{
selemtype *base;
selemtype *top;
int stacksize;
}sqstack;
//顺序栈的初始化操作就是为顺序栈动态分配一个预定义大小的数组空间
status initstack(sqstack &s)
{
s.base = new selemtype[Max];
if (!s.base)
exit(0);
s.top = s.base;
s.stacksize = Max;
return 0;
}
//入栈
status push(sqstack &s, selemtype e)
{
if (s.top - s.base == s.stacksize)
return -1;
*s.top ++= e;
return 0;
}
//出栈
status pop(sqstack &s,selemtype e)
{
if (s.top == s.base)
return -1;
e = *--s.top;
return 0;
}
//取栈顶元素
selemtype gettop(sqstack s)
{
if (s.top != s.base)
{
return *(s.top - 1);
}
}