forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
340 B
21 lines
340 B
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
/***
|
|
问题:将 n 格元素从 A 经过 B 移动到 C
|
|
小数 必须在 大数的上侧,及存在顺序问题
|
|
*/
|
|
func main() {
|
|
run(3, "A", "B", "C")
|
|
}
|
|
|
|
func run(n int, a, b, c string) {
|
|
if n > 0 {
|
|
run(n-1, a, c, b)
|
|
fmt.Println("从【" + a + "】移动到【" + c + "】")
|
|
run(n-1, b, a, c)
|
|
}
|
|
}
|
|
|