在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Go实现: package main import "fmt" func main() { Hanoi(3, 'A', 'B', 'C') } func Hanoi(n int, x, y, z rune) { if n == 0 { //nothing to do } else { Hanoi(n-1, x, z, y) fmt.Printf("%c->%c,", x, y) Hanoi(n-1, z, y, x) } } C实现: #include <stdio.h> #include <stdlib.h> void hanoi(int n, char x, char y, char z); void hanoi(int n, char x, char y, char z) { if(n == 0){ //nothing to do } else { hanoi(n - 1, x, z, y); printf("%c->%c, ", x, y); hanoi(n - 1, z, y, x); } }
|
请发表评论