数据结构问题啊,运行没有结果的

来源:百度知道 编辑:UC知道 时间:2024/06/02 04:51:19
#define error 0
#define ok 1
typedef int status;
typedef int SElemType;
typedef int ElemType;
typedef struct
{
SElemType *base;
SElemType *top;
SElemType stacksize;
}SqStack;
status InitStack(SqStack &s){
// 构造一个空栈
s.base=(SElemType*)malloc(STACK_INIT_SIZE *sizeof(ElemType));
if(!s.base) exit(overflow);
s.top=s.base;
s.stacksize=STACK_INIT_SIZE;
return ok;
}//Initstack
status Push(SqStack &s,SElemType e){
//插入元素e为新的栈顶元素
if(s.top-s.base>=s.stacksize){//栈满,追加存储空间
s.base=(SElemType*)realloc(s.base,
(STACK_INIT_SIZE+STACKINCREMENT) *sizeof(ElemType));
if(!s.base) exit(overflow);//存储分配失败
s.top=s.base;
s.stacksize=STACK_INIT_SIZE+STACKINCREMENT;
}
*s.top++=e;
return ok;
}//Push
status Pop(SqStack &s,SElemType &e){
if(s.top==s.base)return error;
e=*--s.top;
return ok;

大哥,你真粗心啊
status stackEmpty(SqStack &s)
{
if(s.base==s.top) return false;
else return true;
}//stackEmpty

看看对不,应该是
status stackEmpty(SqStack &s)
{
if(s.base==s.top) return true;
else return false;
}//stackEmpty

问题解决了,不过我这里不知道为什么要输入两个数字才有响应
(原因:scanf("%d\n",&N);替换为 scanf("%d",&N);)

这样的东西能编译成功么?
至少应该加上#include <stdio.h>吧?