The following recursive function in C is a solution to the Towers of Hanoi problem.
void move(int n, char A, char B, char C) { if (......................) { move (.............................); printf("Move disk %d from pole %c to pole %c\n", n, A,C); move (.....................); } }
Fill in the dotted parts of the solution.
void move(int n, char A, char B, char C) { if (n > 0) { move (n-1, A, C, B); printf("Move disk %d from pole %c to pole %c\n", n, A, C); move (n-1, B, A, C); } }
The snippet tells that A must be a source and C the destination.That means function would be move(src,spare,dest).
Firstcall(A,B,C) A to C using B intermediate
If we go by this defination, first move(n-1,A,C,B) will move n-1 disks to B using C as spare.
Now the 1 that remains is moved from A(src) to C(dest).
Shouldn't the last call then be move(n-1,B,A,C) ,that is moving the n-1 disk that were previously moved to intermediate node B over C(the destination) ?
need updation of this ans
https://gateoverflow.in/163078/tower-of-hanoi?state=comment-163092&show=163092#c163092