顺序栈
存储结构定义
typedef int ElemType;
typedef enum Status{
ERROR = 0,OK = 1
}Status;
typedef struct SqStack{
ElemType *elem;
int top; //用于栈顶指针
int size; // 最大大小
}SqStack;
初始化栈
//顺序栈(基于数组的)
Status initStack(SqStack *s,int sizes) //初始化
{ s->elem = (ElemType *)malloc(sizes * sizeof(ElemType));
if (s->elem == NULL) {
return ERROR;
}
s->top = -1;
s->size = sizes;
t = 1; //表示已经初始化
return OK;
}
判空
Status isEmptyStack(SqStack *s){
return ( s->top == -1 ? OK : ERROR);
}
取得栈顶元素
Status getTopStack(SqStack *s,ElemType *e){
if (s == NULL || s->top == -1