#define StackSize 100
typedef int ElemType;
typedef struct {
ElemType elem[StackSize];
int top;
}SqStack;
InitStack(SqStack *pS)
{
pS->top=0; /* top指向栈顶的上一个元素 */
}
int Push(SqStack *pS,ElemType e)
{
if (pS->top==StackSize-1) /* 栈满 */
return 0;
pS->top=pS->top+1;
pS->elem[pS->top]=e;
return 1;
}
int Pop(SqStack *pS,ElemType* pe)
{
if (pS->top==0) /* 栈空 */
return 0;
*pe = pS->elem[pS->top];
pS->top = pS->top - 1;
return 1;
}
阅读(889) | 评论(1) | 转发(0) |