#include<stdio.h>
//#include<string.h>
//#include<math.h>
#include<stdlib.h>
//函数结果状态代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define NULL 0
#define MAXSIZE 100
//Status是函数的类型,其值是函数结果状态代码
typedef int Status;
//声明结点的类型和指向结点的指针类型
typedef struct {
SElemType *base;//栈底指针
SElemType *top;//栈顶指针
int stacksize;//栈可用最大容量
}SqStack;
//初始化
Status InitStack(SqStack &S){
S.base=(SElemType*)malloc(MAXSIZE*sizeof(SElemType));
if(!S.base) exit(OVERFLOW);//存储分配失败
S.top=S.base;//栈顶指针=栈底指针->栈空
S.stacksize=MAXSIZE;
}
//判断栈是否为空
Status StackEmpty(SqStack S){
if(S.top==S.base) return TRUE;
else return FALSE;
}
//求顺序栈长度
int StackLength(SqStack S){
return S.top-S.base;
}
//清空顺序栈
Status ClearStack(SqStack S){
if(S.base) S.top=S.base;
return OK;
}
//销毁顺序栈
Status DestoryStack(SqStack S){
if(S.base){
free(&S.base);
S.stacksize=0;
S.base=S.top=NULL;
}
return OK;
}
//顺序栈入栈
Status Push(SqStack &S,SElemType e){
if(S.top-S.base==S.stacksize) return ERROR;//栈满
*S.top++=e;//等价于*S.top=e;S.top++;
return OK;
}
//顺序栈出栈
Status Pop(SqStack &S,SElemType &e){
if(StackEmpty(S)) return ERROR;//栈空
e=*--S.top;//等价于--S.top;e=*S.top;
return OK;
}
int main(){
return 0;
}