栈的顺序实现
时间:2009-03-28 来源:jia_killer
#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;
}
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;
}
相关阅读 更多 +