#include
#include
#define max 6
typedef struct Stack
{
int arr[max];
int val;
int top;
}stack;
stack *pst;
int isfull(stack *p)
{
return p->top==max-1;
}
void push(stack *p,int data)
{
if(!isfull(p))
{
p->arr[++(p->top)]=data;
}
}
int isempty(stack *p)
{
return p->top==-1;
}
int pop(stack *p)
{
if(!isempty(p))
{
return (p->arr[p->top--]);
}
else
exit (0);
}
int main()
{
pst=(stack*)malloc(sizeof(struct Stack));
pst->top=-1;
int num,r;
int i;
for(i=0;iscanf("%d",&num);
push(pst,num);
}
for(i=0;ipop(pst);
printf("%d ",r);
}
}
能不能帮我看看我写的顺序栈对不对
问题描述:
1、定义一个顺序栈,输入测试数据, 分别根据其中的命令字符来处理堆栈;
(1)对所有的’P’操作,如果栈满输出’F’,否则完成压栈操作;
(2)对所有的’A’操作,如果栈空,则输出’E’,否则输出当时栈顶的值;
(3)对所有的’O’操作,如果栈空,则输出’E’,否则输出栈顶元素的值,并让其出栈;
基本可以,达到预期效果就可以啊。数组顺序存放,top是栈顶的位置,判断空/满,思路没问题