下面是我的代码,一运行就只能输出一个字符:
typedef struct{
char elem[StackSize];
int top;
int base;
}SeqStack;
void InitStack(SeqSta
char Push(SeqStack *S,char x){ //元素进栈 ,需要判断栈满
if(S->top==StackSize-1)
return FALSE;
S->top++;
S->elem[S->top]=x;
return (TRUE);
}
char Pop(SeqStack *S,char *x){ //出栈 ,需要判断栈空
if(S->top==-1)
return (FALSE);
else{
*x=S->elem[S->top];
S->top--;
return (TRUE);
}
}
char GetTop(SeqStack *S,char *x){ //取栈顶元素
if(S->top==-1)
return (FALSE);
else{
*x=S->elem[S->top];
return (TRUE);
}
}
int StackLength(SeqStack *S)
{
int length;
length=S->top+1-S->base;
printf("栈长度为:%d\n",length);
}
void showStack(SeqStack *S){
int i;
if(S==NULL||S->top==-1){
printf("ERROR");
}
printf("输出栈:");
for(i=S->top;i>=0;i--){
printf("%c ",S->elem[i]);
}
}