#include
#include
#define Max 100;
#define error 0;
#define ok 1;
typedef int SElemType;
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
int Status InitStack(SqStack &s)
{
if(!s.base)exit(OVERFLOW);
s.top=s.base;
s.stacksize=Max;
return ok;
}
int StackFull(SqStack s)
{
if(s.top-s.base==s.stacksize)
{
return 1;
}
else{
return 0;
}
}
int StackEmpty(SqStack s)
{
if(s.top==s.base)
{
return 1;
}
else{
return 0;
}
}
void Status Push(SqStack &s,SElemType e)
{
if(StackFull(s))return error;
*s.top=e;
s.top++;
}
int Status Pop(SqStack &s,SElemType &e)
{
if(StackEmpty(s))return error;
s.top--;
e=*s.top;
return ok;
}
int main()
{
int i=1;
SqStack stack1;
InitStack(&stack1);
for(i=1;i<=10;i++)
{
Push(&stack1,i);
}
return 0;
}
if(!s.base)exit(OVERFLOW); base你都没分配空间啊
#define Max 100;
#define error 0;
#define ok 1;
#define后面是不能加分号的啊
InitStack(&stack1);
Push(&stack1,i);
这两个函数调用的&符号去掉,参数是引用,不是指针
错误有点多,可以参考一下文章修改一下http://t.csdn.cn/6ZNKj
你可以看下我博客,栈和队列,顺序表和单链表的形式都有