#include
#include
typedef struct sq
{
char *ps;
int top;
int Maxsize;
}stack;
void initstack(stack *s,int ms)
{
s->ps=(char*)malloc(ms*sizeof(char));
s->top=-1;
s->Maxsize=ms;
};
void push(stack *s,char val)
{
if(s->top==s->Maxsize-1)
{
printf("栈已满\n");
return ;
}
s->ps[++s->top]=val;
};
char pop(stack *s)
{
char k;
if(s->top==-1) return 1;
k=s->ps[s->top];
s->top--;
return k;
};
void push_queue(stack *s1,stack* s2)
{
char val ;
scanf("%c",&val);
push(s1,val);
}
void pop_queue(stack *s1,stack *s2)
{
char x;
if(-1==s2->top)
{ while(-1!=s1->top)
{
x=pop(s1);
push(s2,x);
}
} while(-1!=s2->top){ x=pop(s2);printf("%c",x);}
}
int main(int argc,char **argv)
{
stack s1,s2; int i;
printf("输入进队序列\n");
initstack(&s1,10); initstack(&s2,10);
for(i=0;i<10;i++) push_queue(&s1,&s2);
printf("出对序列为:\n");
pop_queue(&s1,&s2);
return 0;
}