The code for the Towers of Hanoi is here, the problem is what will the rest of the recursive calls be?
//provided in the main method that String Src="Src", Aux="Aux", Dst="Dst";
public static void solve (int diskNumber, String Src, String Aux, String Dst) {
if (diskNumber ==0)
return;
else
{
solve(diskNumber-1, Src, Dst, Aux);
System.out.println("Move the disk from "+Src +" to "+Dst);
solve(diskNumber-1, Aux, Src, Dst);
}
}
For example, we solve the 3 disks, we call solve(3, Src, Aux, Dst), the next recursive call will be (2, Src, Dst, Aux). I understand this so far, but what will happen from then on? What are the rest of the recursive calls?
What I don't get is when and how are the println and the "solve(diskNumber-1, Aux, Src, Dst)" executed, why?
I first thought it might be
(3, A, B, C) Src= A; Aux=B; Dst=C;
(2, A, C, B)
(2, B, A, C)
(1, A, C, B)
(1, B, A, C)
N=0, exit
but I don't think it's right.
Thanks!