办法扭转队列只用了两个临时队列,仅此而已?队列、仅此而已、两个、办法

由网友(–Harbor 两岸相观不相关)分享简介:有没有办法扭转项目中只使用了两个临时队列队列顺序(没有其他变量,如柜台)?只有标准的队列操作可用:ENQUEUE(E),DEQUEUE(),空()? Is there a way to reverse items' order in queue using only two temporary queues (and...

有没有办法扭转项目中只使用了两个临时队列队列顺序(没有其他变量,如柜台)?只有标准的队列操作可用:ENQUEUE(E),DEQUEUE(),空()?

Is there a way to reverse items' order in queue using only two temporary queues (and no other variables, such as counters)? Only standard queue operation are available: ENQUEUE(e), DEQUEUE(), EMPTY()?

在任何语言或伪code解决方案是值得欢迎的。

Solutions in any language or pseudocode are welcome.

推荐答案

您可以:

使用两个队列模拟堆栈。 按所有原始队列中的元素来这个堆栈中。 现在,从栈中弹出的每个元素,并把它添加到原始队列。
阅读全文

相关推荐

最新文章