开发者

Filling a queue from another queue in reverse order

开发者 https://www.devze.com 2023-02-18 06:00 出处:网络
It is also too easy maybe. How can I 开发者_开发知识库fill the B queue by A queue? but B queue must be reverse.What about just

It is also too easy maybe. How can I 开发者_开发知识库fill the B queue by A queue? but B queue must be reverse.


What about just

val b = a.reverse


Assuming Queue is a FIFO, if you can take from the end of the queue, just take from the end of A and put them into B.

If you can't, take A from the front, insert them on a Stack, then when A is empty, put them off the stack into B.

0

精彩评论

暂无评论...
验证码 换一张
取 消