Redian新闻
>
问一道crack tech interview里面的题
avatar
问一道crack tech interview里面的题# JobHunting - 待字闺中
v*n
1
#3.4
In the classic problem of the Towers of Hanoi, you have 3 rods and N disks
of 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 constraints:
(A) Only one disk can be moved at a time.
(B) A disk is slid of 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.
初始的时候,这些disks已经在第一个rod上了吧,也就是说input已经是sorted stack
,对吗?
谢谢。
avatar
c*p
2
是的。。这个问题的中文名字叫汉诺塔。

disk

【在 v***n 的大作中提到】
: #3.4
: In the classic problem of the Towers of Hanoi, you have 3 rods and N disks
: of 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 constraints:
: (A) Only one disk can be moved at a time.
: (B) A disk is slid of 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.

avatar
v*n
3
谢了!
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。