菜鸟一只,各位大虾看下是为什么运行不了,不知道哪里出错了~~~
/*顺序栈的基本操作*/
#include <stdio.h>
#define MaxSize 100
typedef char ElemType;
typedef struct
{
char stack[MaxSize];
int top;
} stacktype;
void initstack(stacktype *S)
{
S->top=-1;
}
void push(stacktype *S,ElemType x)
{
if (S->top==MaxSize) printf("栈上溢出!\n");
else
{
S->top++;
S->stack[S->top]=x;
}
}
void pop(stacktype *S)
{
if (S->top==-1) printf("栈下溢出!\n");
else S->top--;
}
ElemType gettop(stacktype *S)
{
if (S->top==-1) printf("栈空!\n");
else return(S->stack[S->top]);
}
int empty(stacktype *S)
{
if (S->top==-1) return(1);
else return(0);
}
void display(stacktype *S)
{
int i;
printf("栈中元素:");
for (i=S->top;i>=0;i--)
printf("%c ",S->stack[i]);
printf("\n");
}
main()
{
stacktype *st;
printf("建立一空栈\n");
initstack(st);
printf("栈空:%d\n",empty(st));
printf("依次插入a,b,c,d元素\n");
push(st,'a');
push(st,'b');
push(st,'c');
push(st,'d');
display(st);
printf("退一次栈\n");
pop(st);
printf("栈顶元素:%c\n",gettop(st));
printf("退一次栈\n");
pop(st);
display(st);
}
谢谢~~