栈的基础代码
SqStack * InitStack()//初始化 {
SqStack *s;
s=(SqStack *)malloc(sizeof(SqStack));
s->top=-1;
return s;
}
int LengthStack(SqStack *s)//求长度
{
return(s->top+1);
}
int EmptyStack(SqStack *s)//判空
{
return (s->top==-1);
}
int PushStack(SqStack *s,int x)//入栈
{
if(s->top==Maxsize-1)
{
return 0;
}
s->top++;
s->data[s->top]=x;
return 1;
}
int PopStack(Sqstack *s,int *x)//出栈
{
if(s->top==-1)
{
return 0;
}
*x=s->data[s->top];
s->top--;
return 1;
}
void DisStack(SqStack *s)//打印
{
int i;
for(i=s->top;i>=0;i--)
{
printf("%d",s->data[i]);
}
}