高手们帮我找错啊。。。。

来源:百度知道 编辑:UC知道 时间:2024/09/20 10:58:25
#include<stdio.h>
#include<malloc.h>
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define ERROR 0
#define OK 1
#define OVERFLOW -2
typedef int Status;
typedef char SElemType;
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) return ERROR;
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}
Status Push(SqStack S,SElemType e)
{
if(S.top-S.base>=STACK_INIT_SIZE)
{
S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
if(!S.base) exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
return OK;
}
Status Pop(SqStack S,SElemType e)
{
if(S.top==S.base) return ERROR;
e=* --S.top;
retu

#include<stdio.h>
#include<malloc.h>

#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define ERROR 0
#define OK 1
#define OVERFLOW -2
typedef int Status;
typedef char SElemType;
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) return ERROR;
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return OK;
}
Status Push(SqStack S,SElemType e)
{
if(S.top-S.base>=STACK_INIT_SIZE)
{
S.base=(SElemType *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(SElemType));
if(!S.base)
//exit(OVERFLOW); //exit没有定义;
return OVERFLOW; //添加这一句来替换上面那句
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top++=e;
re