Foreword:During the recursive process, the book was used as an example of the Hanoi Tower. There are very few code, but I do not understand the principle of writing, so I gradually analyzed and recorded the changes of each variable, and expressed its processes in the form of figures in the form of figures. , For future review!
———————————————————————————————————————————————————————————–
Program code (three -order examples):
#include <stdio.h>
void Hanoi (Int n, char a, char b, char) // Move the n disc from the A -pillar to the C -pillar, and use B as the auxiliary column
{{
if (n == 1)
{{
Printf (" %c-> %c \ n", a, c); // Move the disc from A to C
}
else
{{
hanoi (n-1, a, c, b); // Move the disc number 1 to N-1 on A to B, C as auxiliary tower
Printf (" %c-> %c \ n", a, c); // Move the disc from A to C
hanoi (n-1, b, a, c); // Move the disc number 1 to N-1 on B to C, A as auxiliary tower
}
}
int Main (int argc, char ** argv) {
hanoi (3, 'a', 'b', 'c'); // third -order Hanoi Tower
Return 0;
}
diagram analysis:
Among them, I think the understanding and assignment problem of the understanding and assignment of HANOI (INT N, Char A, Char B, Char C) each time is where the understanding and assignment of the cosmetics of C, and c, it is a place that plagues me.
Welcome to discuss the problem together!
If there are incorrect places, please do not rigid!
Thank you for reading!