Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17342
  • 博文数量: 12
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2014-04-29 08:49
文章分类

全部博文(12)

文章存档

2014年(12)

分类: IT职场

2014-07-13 11:15:54

Show how to implement a stack using two queues. Analyze the running time of the stack operations.

We have two queues and mark one of them as active. PUSH queues an element on the active queue. POP should dequeue all but one element of the active queue and queue them on the inactive. The roles of the queues are then reversed, and the final element left in the (now) inactive queue is returned.

The PUSH operation is Θ(1), but the POP operation is Θ(n) where n is the number of elements in the stack.

阅读(366) | 评论(0) | 转发(0) |
0

上一篇:CLRS 6.5-8

下一篇:把数组排成最小的数

给主人留下些什么吧!~~