栈的结构定义:
typedef int SElemType;
typedef struct
{
SElemType data[MAXSIZE];
int top;
} SqStack;
进栈和出栈操作:
Status Push(SqStack *S, SElemType e)
{
if(S->top == MAXSIZE - 1)
{
return ERROR;
}
S->top++;
S->data[S->top] = e;
return OK;
}
Status Pop(SqStack *S, SElemType *e)
{
if(S->top== -1)
return ERROR;
*e=S->data[S->top];
S->top--;
return OK;
}
两栈共享空间
typrdef struct
{
SElemType data[MAXSIZE];
int top1;
int top2;
} SqDoubleStack;
判断栈满的方式: s->top1 + 1 == S -> top2 该表达式为true