帮忙看看,堆栈不能初始化
#include "stdio.h"#define MAXSIZE 50
#define NULL 0
#define TRUE 1
typedef int datatype;
typedef struct
{
datatype stack[MAXSIZE];
int top;
}seqstack;
seqstack *s;
void INITSTACK(seqstack *s)
{
s->top=-1;
}
int EMPTY(seqstack *s)
{
if(s->top <0)
return TRUE;
else return NULL;
}
seqstack *push(seqstack *s,datatype x)
{
if(s->top ==MAXSIZE-1)
{ printf("the stack is full\n");
return NULL;
}
else
{
s->top++;
s->stack[s->top]=x;
}
return s;
}
datatype pop(seqstack *s)
{
datatype x;
if(EMPTY(s))
{
printf("the stack is empty\n");
return NULL;
}
else
{
x=s->stack[s->top];
s->top--;
}
return x;
}
void main()
{
datatype x;
int n=0;
INITSTACK(s);
printf("input number and as -1 to end\n");
scanf("%d",&x);
while(x!=-1)
{
s=push(s,x);
n++;
scanf("%d",&x);
}
printf("n=%d\n",n);
while(EMPTY(s)!=1)
{
x=pop(s);
printf("%d ",x);
n--;
}
printf("n=%dn",n);
getchar();
}