火车进站问题!!!!!!!!!!
火车进站,出站问题,用栈知识解示例:
输入:3 123 321
3 123 312
输出:Yes.
in
in
in
out
out
out
FINISH
No.
FINISH
最前面的3是火车量数,紧接着就是车号,再就是出车顺序,如果不满足直接输出No.看示例
如果能就输出Yes再输出相应的in out,我初学栈,请大侠看看程序怎样继续下去
#include <stdio.h>
#define MAX 20
typedef struct
{
char str[MAX];
int top;
}stack;
void empty(stack *s)
{
s=>top=-1;
}
int push(stack *s,char x)
{
if(s->top==MAX)return 0;
s->top++;
s->str[s->top]=x;
return 1;
}
int pop(stack *s,char *x)
{
if(s->top==-1) return 0;
else
{
*x=s->str[s->top];
s->top--;
return 1;
}
}
int main()
{
int n;
void empty(stack *s);
int push(stack *s,char x);
int pop(stack *s,char *x);
stack stack q;
while(scanf("%d",&n)!=EOF)
{
empty(&q);
q.top=n;
while(c=getchar()!='\n')
push(&q,c);
}
return 0;
}