"Data Structure" recursive algorithm-Hanoi

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.