The problem of Hanoi is also a classic recursive algorithm problem.
The following is a summary of their own overall flowchart.
Here is the code, although the code is simple, but it is important to understand how it works inside.
======================================================================//// Copyright (C) 2014-2015 SCOTT //All rights reserved //// filename:hannuota.c // description:a Demo To display Hannuota //// created by SCOTT at 02/10/2015 // http://blog.csdn.net/ Scottly1 // //====================================================================== #include < stdio.h>void Hannuota (int n, char A, char B, char c) {if (n < 1) return; Hannuota (N-1, A, C, b);p rintf ("Move the plate%d through%c to%c\n", N, A, c); Hannuota (n-1, B, A, c);} int main () {int num;printf ("Input the NUM want to create:"); scanf ("%d", &num); Hannuota (num, ' A ', ' B ', ' C '); return 0;}
Operation Result:
If you have doubts about the algorithm of the computer, you can calculate it by yourself and see if it is the best method.
Original article, reprint please famous source: http://blog.csdn.net/scottly1/article/details/43705291
"Data Structure" recursive algorithm-Hanoi