0
Explanation Hanoi Code (Recursion)
Hello, Can you explain how the following code works? Especially, what does n-1 and how do you modify the variables? package Semana2_Recursion; public class Hanoi { public static void main(String[] args) { solucionar('A','B','C', 2); // Llamado inicial con 2 discos } public static void solucionar(char A, char B, char C, int n) { if (n>0) { solucionar(A,C,B,n-1); System.out.println("Movimiento "+A+"->"+C); solucionar(B,A,C, n-1); } } }
1 ответ
+ 1
just tace this with pen and paper for 3 disk you will get the idea for n disks.