求助顺序栈的程序哪里出错创建不得
//顺序栈的基本操作#include<stdio.h>
#include<stdlib.h>
#define MAX 100
typedef int DataType;
struct SeStack
{
DataType elem[MAX];
int top;
};
struct SeStack *s;
struct SeStack *StackInit();
struct SeStack *StackCreat();
int StackEmpty(SeStack *s);
int StackFull(SeStack *s);
void ClearStack(SeStack *s);
int LengthStack(SeStack *s);
void StackPush(SeStack *s,DataType x);
DataType StackPop(SeStack *s);
DataType StackGetTop(SeStack *s);
void Stackprint(SeStack *s);
int main(void)
{
struct SeStack *p,*q;
p=(SeStack *)malloc(sizeof(SeStack));
q=(SeStack *)malloc(sizeof(SeStack));
p=StackInit();
printf("是否为空栈:%d\n",StackEmpty(p));
q=StackCreat();
Stackprint(q);
return 0;
}
struct SeStack *StackInit()
{
SeStack *s;
s=(SeStack *)malloc(sizeof(SeStack));
s->top=-1;return s;
}
SeStack *StackCreat()
{
SeStack *r;int k;
r=(SeStack *)malloc(sizeof(SeStack));
printf("输入入栈数据,以-1作为结束标记\n");
scanf("%d",&k);
while(k!=-1)
{
r->elem[s->top]=k;
r->top++;
}
return r;
}
int StackEmpty(SeStack *s)
{
if(s->top=-1)return -1;
else return 0;
}
int StackFull(SeStack *s)
{
if(s->top=MAX-1) return -1;
else return 0;
}
void ClearStack(SeStack *s)
{
s->top=-1;
free(s);
}
int LengthStack(SeStack *s)
{
return (s->top+1);
}
void StackPush(SeStack *s,DataType x)
{
if(s->top==MAX-1) printf("栈满");
else
{
s->top++;
s->elem[s->top]=x;
}
}
DataType StackPop(SeStack *s)
{
DataType x;
if(StackEmpty(s)) return 0;
else
{
x=s->elem[s->top];s->top--;
return x;
}
}
DataType StackGetTop(SeStack *s)
{
if(StackEmpty(s)) return 0;
else
{
return s->elem[s->top];
}
}
void Stackprint(SeStack *s)
{
DataType k;
while(s->top!=-1)
{
printf("%d\n",s->elem[s->top]);
k=StackPop(s);
}
}