Home > ハノイの塔


Javaでのハノイの塔の実装方法

public class HanoiTower { public static void main(String[] args) { int discs = 3; // タワーのディスクの数 char source = 'A'; // 出発地点の塔 char auxiliary = 'B'; // 仮の塔 char destination = 'C'; // 目的地の塔 solveHanoi(discs, source, auxiliary, destination); } public s>>More


Javaでのハノイの塔の解法

public class TowersOfHanoi { public static void solve(int n, char source, char auxiliary, char destination) { if (n == 1) { System.out.println("Move disk 1 from " + source + " to " + destination); return; } solve(n - 1, source, destination, auxili>>More