定义
#define MAXSIZE 100
typedef struct
{
int data[MAXSIZE];
int top;
}SqStack;
SqStack S;
初始化栈
void InitStack(SqStack *S)
{
S->top = -1;
}
清空栈
int ClearStack(SqStack *S)
{
S->top = -1;
return true;
}
判栈空
int StackEmpty(SqStack *S)
{
if(S.top == -1)
return true;
else
return false;
}
判栈满
int StackFull(SqStack *S)
{
if(S->top == MAXSIZE - 1)
return true;
else
return false;
}
栈长
int StackLength(SqStack *S)
{
return S->top+1;
}
返回栈顶元素
int GetTop(SqStack S, int *e)
{
*e = S.data[S.top];
return true;
}
显示元素
int DispStack(SqStack S)
{
int i = 0;
while(i<S.top)
printf("%d ",S.data[I++]);
return true;
}
入栈
int Push(SqStack *S, int e)
{
S->top++;
S->data[S->top] = e;
return true;
}
出栈
int Pop(SqStack *S, int *e)
{
//先判栈空
*e = S->data[S->top];
S->top--;
return true;
}