#define StackInintSize 100 //初始栈的大小
#define StackCrement 10 // 后面进栈的时候可能栈大小不够 这是预设的增量
typedef struct SqStack{ //栈结构体
int *base;
int top;
int stacksize;
}S;
void InitSqStack(SqStack &S){
S.base=(int *)malloc(StackInintSize*sizeof(int));
if(!s.base){
return;
}
S.top=0;
S.stacksize=StackInintSize;
}
int StackEmpty(SqStack S){
if(S.top == 0){
return 1;
}
return 0;
}
int StackLength(SqStack S){
return S.top;
}
void Push(SqStack &S, int e){
if(S.top == S.stacksize){
S.base=(int *)malloc((StackInintSize+StackCrement)*sizeof(int));
if (!S.base){
return;
}
S.stacksize += StackCrement;
}
S.top=e;
S.top++;
}
void GetTop(SqStack S,int &e){
if(S.top == 0){
return;
}
e=S.top;
S.top--;
S.base--;
}