Recursion Tree for Hanoi
Figure below shows the recursion tree for a 3 disk problem

Collect together all the shift moves to have the final solution:

Attached is the beautiful recursive code for Towers of Hanoi done in C++ using the pseudo-code given previously. As you can see, it is a direct translation of the pseudo-code we wrote beforehand.
xxxxxxxxxx16
function shift(shelf1, shelf2) {  console.log("Shift from " + shelf1 + " to " + shelf2);}​function Hanoi(N, source, destination, intermediate) {  // base case  if (N === 0)    return;  // recursive case  Hanoi(N - 1, source, intermediate, destination);  shift(source, destination);  Hanoi(N - 1, intermediate, destination, source);}​// example call for the illustrated problemHanoi(3, 'A', 'B', 'C');OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment


