如何用Go语言实现汉诺塔算法

package main

import (
    "fmt"
)

func print(n int,x rune,y rune)(){
    fmt.Printf("moving disk %d from pole %c to pole %c\n",n,x,y)
}

func move(n int,a rune,b rune,c rune)(){
    if n==1{
        print(n,a,c)
    }else {
        move(n-1,a,c,b);
        print(n,a,c);
        move(n-1,b,a,c)
    }
}

func main() {
    var n int;
    fmt.Println("Please input the disk number n: ");
    fmt.Scanf("%d",&n);
    move(n,'x','y','z')
     }

 

posted @ 2017-04-17 10:25  iVictor  阅读(795)  评论(0编辑  收藏  举报