Recursive functions of C + +

Source: Internet
Author: User

Recursive implementation of the Hanoi tower problem.

Have to say very complicated, think of a night just figured out the implementation of the process, do not know which great man to come out of, unexpectedly recursive use so superb, I can not wait.

1#include <iostream>2 using namespacestd;3#include <string>4 5 voidMoveCharXChary)6 {  7cout<<x<<" -"<<y<<Endl; 8 } 9 Ten  One voidFintNCharOneCharBoth,Charthree) { A     if(n = =1){ - Move (one,three); -}Else{ the         //first, the n-1 plate on A is moved to B by means of C, -         //then move the last large plate on a to C, -        //Finally, the n-1 plate on B is borrowed from Group A to C . -F (N-1, one,two,three); + Move (one,three); -F (N-1, two,one,three); +     } A } at intMain () { -      intm;  -cout<<"Enter the number of plates:";  -Cin>>m;;  -F (M,'A','B','C');  -}

Recursive functions of C + +

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.