首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Chapter 三 Stacks and Queues - 3.4

2012-07-15 
Chapter 3 Stacks and Queues - 3.4Problem 3.4: In the classic problem of the Towers of Hanoi, you ha

Chapter 3 Stacks and Queues - 3.4
Problem 3.4: In the classic problem of the Towers of Hanoi, you have 3 rods and N disks fo different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from top to bottom (e.g., each disk sits on top of an even larger one). You have the following constrains:
(A) Only one disk can be moved at a time.
(B) A disk is slid off the top of one rod onto the next rod.
(C) A disk can only be placed on top of a larger disk.
Write a program to move the disks from the first rod to the last using Stacks.


So classic, so recursive:P


热点排行