一个栈的问题
程序代码:#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 20
typedef int SElemType;
typedef int Status;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
Status initStack(SqStack S)
{
S.base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(!S.base) exit(ERROR);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}
void push_stack_sq(SqStack S,SElemType e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
if(!S.base) exit(ERROR);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top=e;
S.top++;
}
void print(SqStack S)
{ SElemType *p;
p=S.base;
while(p<=S.top)
{
printf("%d ",*p);
p++;
}
}
int main()
{
SqStack S;
initStack(S);
push_stack_sq(S,5);
push_stack_sq(S,4);
push_stack_sq(S,3);
print(S);
}为什么结果出不来?哪里出错了?








