#include"Queue.h"
#include"Stack.h"
bool reverse(Queue &Q,int n)
{
/************Begin*******************/
int k;
Stack Q1;
InitStack(Q1);
while(Q.rear!=Q.front)
{
DeQueue(Q,k);
Push(Q1,k);
}
while(n--)
{
Pop(Q1,k);
cout<<k<<" ";
}
/************End*********************/
}
int main()
{
Queue Q;
InitQueue(Q);
int n,x;
cin>>n;
for(int i = 0; i < n; i ++)
{
cin >>x;
EnQueue(Q,x);
}
if(reverse(Q,n))Traverse(Q);
return 0;
}
第2关:队列元素逆置
最新推荐文章于 2024-08-08 15:12:59 发布