开发者

turning an abstract queue upside down with stack

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜