顺序栈问题很疑惑
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
#define MAX 100
typedef struct
{
int data[20];
int top;
}sqstack;
void inti(sqstack *s)
{
s->top=0;
printf("初始化队列成功!\n");
}
int emptystack(sqstack *s)
{
if(s->top==0)
return (1);
else
return (0);
}
int Fullstack(sqstack *s)
{
if(s->top==20)
{
return (1);
}
else
{
return (0);
}
}
void pushstack(sqstack *s,int x)
{
if(Fullstack(s))
{
printf("顺序栈为满!\n");
}
else
{
s->data[s->top]=x;
s->top++;
printf("压栈成功!\n");
}
}
void print(sqstack *s)
{
int p;
p=s->top-1;
printf("%d\n",p);
if(s->top==0)
printf("stack is NULL!\n");
else
while(p>=0)
{
printf("%d ",s->data[p]);
p=p--;
}
printf("\n");
}
int popstack(sqstack *s)
{
int e;
if(emptystack(s))
{
printf("顺序栈为空!\n");
}
else
{
s->top--;
e=s->data[s->top];
return e;
}
}
int main()
{
sqstack *s;int x;
s=(sqstack *)malloc(sizeof(sqstack));
inti(s);
pushstack(s,1);
pushstack(s,2);
pushstack(s,3);
pushstack(s,4);
print(s);
x=popstack(s);
printf("弹栈的元素为%d\n",x);
return 0;
}
这个程序是我自己写的,有问题吗