栈的简单介绍💕❤🤞
栈
顺序栈
typedef struct {
SElemType *base;
SElemType *top;
int stacksize;
}Sqstack;
Status initStack(Sqstack &S){
S.base = new SElemType[stack_INIT_SIZE];
S.top = S.base;
S.stacksize = stack_INIT_SIZE;
return OK;
}
Status push(Sqstack &S, SElemType x){
if(S.stacksize <= (S.top - S.base)){
S.base = (SElemType *)realloc(S.base, ((S.stacksize + stack_INIT_SIZE)));
if(S.base != NULL){
return ERROR;
}
S.top = S.base + S.stacksize;
S.stacksize = S.stacksize + stack_INIT_SIZE;
}