Hanoi Tower Problem

Source: Internet
Author: User

Legend has it that in the ancient Indian Sheng Miao, a yellow copper plate was planted, and three pillars were inserted on the board (A, B and C pillars), and on a treasure pillar, from top to bottom, there were 64 gold plates in the order from small to large. The 64 gold plates on the A pillar are required to be moved to the C column according to the following rules.
③ at any time the market can not be placed on the small plate.
Task: Enter a positive integer n (the number of plates on a column), and the output moves to the C post.
Analysis: Set A on a there are n plates.
1. When N=1, move the disc from a directly to C.
2. When n=2, then:
① move the 1 discs on a to B;
The ② then moves a disc on a to C;

The ③ finally moves the 1 discs on the B to C.

★ ¡ï have the code is good to do.

Code to serve.

#include <stdio.h>voidHanoiintNCharACharBCharC) {    if(n==1) printf ("%c→%c", A,c); Else{Hanoi (n-1, a,c,b); printf ("%c→%c\n", A,c); Hanoi (n-1, B,a,c); }}intMain () {Hanoi ( -,'X','Y','Z'); }    

Downloads for C + + and dev-c++

Hanoi Tower Problem

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.