关于栈的插入的调试,请高手看看错在哪里
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
#define STACK_INT_SIZE 100
#define STACKINCRMENT 10
#define ERROR 0
#define OK 1
typedef int Status;
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
int InitStack(SqStack &S)
{
S.base=(SElemType *)malloc(STACK_INT_SIZE*sizeof(SElemType));
if(!S.base)
{
printf("OVERFLOW");
exit(-1);
}
S.top=S.base;
S.stacksize=STACK_INT_SIZE;
return OK;
}//InitStack;
Status Push(SqStack S,SElemType &e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(SElemType*)realloc(S.base,(S.stacksize+STACKINCRMENT)*sizeof(SElemType));
if(!S.base)
{
printf("OVERFLOW");
exit(-1);
}
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCRMENT;
}
*S.top++=e;
return OK;
}//push
main()
{
SqStack S;
InitStack(S);
Push(&S,1);
system("pause");
}
[ 本帖最后由 尘埃落雪 于 2010-10-22 10:41 编辑 ]