开发者

turning an abstract queue upside down with stack

开发者 https://www.devze.com 2023-03-27 21:54 出处:网络
Why does it take 4n calls to turn 开发者_如何转开发an abstract queue upside down with the help of an abstract stack? Somebody care to help me with this question please?I assume you want the nodes to e

Why does it take 4n calls to turn 开发者_如何转开发an abstract queue upside down with the help of an abstract stack? Somebody care to help me with this question please?


I assume you want the nodes to end up in the original queue. In that case you have to remove all the nodes from the queue one at a time, pushing each onto the stack. So far that's one read (from the queue) and a push (onto the stack). Then you have to pop nodes off the stack and put them back on the queue. That's 4 operations per node.

0

精彩评论

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