Hanoi塔

作者: 柳仁儿 | 来源:发表于2017-09-08 15:11 被阅读0次

```

<h1>

public class Hanoi {

public static void moveOne(char from, char to) {

System.out.println(from + "->" + to);

}

public static void move(char from, char to, char aux, int n) {

if (n == 1) {

moveOne(from, to);

return;

}

move(from, aux, to, n - 1);

moveOne(from, to);

move(aux, to, from, n - 1);

}

public static void main(String[] args) {

int n = 1000;

move('A', 'B', 'C', n);

}

}

```

相关文章

网友评论

      本文标题:Hanoi塔

      本文链接:https://www.haomeiwen.com/subject/ibngjxtx.html