def hanoi( n, origin, assist, destination): if (n == 1) : move(origin, destination) else: hanoi(n - 1, origin, destination, assist) move(origin, destination) hanoi(n - 1, assist, origin, destination)
def move( origin, destination) : print("Direction:" + origin + "--->" + destination)
hanoi(3, 'A', 'B', 'C')
Sign in to make a reply
MusicMakeMeHappy
public class Hanoi {
/**
*
* @param n 盘子的数目
* @param origin 源座
* @param assist 辅助座
* @param destination 目的座
*/
public void hanoi(int n, char origin, char assist, char destination) {
def hanoi( n, origin, assist, destination): if (n == 1) : move(origin, destination) else: hanoi(n - 1, origin, destination, assist) move(origin, destination) hanoi(n - 1, assist, origin, destination)
// Print the route of the movement
def move( origin, destination) : print("Direction:" + origin + "--->" + destination)
public static void main(String[] args) {
Hanoi hanoi = new Hanoi();
hanoi(3, 'A', 'B', 'C')