C # Hanoi)

Source: Internet
Author: User

When God created the world, he made three diamond pillars and placed 64 gold disks in order from bottom to bottom.
God ordered the Brahman to re-place the disc from below in order of size on another pillar. It is also stipulated that the disc cannot be enlarged on a small disc, and only one disc can be moved between the three pillars at a time.

It was predicted that the universe would flash into destruction at the completion of the event. Some people believe that Brahman is still moving the disc for a moment.

 

The recursive principle is used.

Code:

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;

Namespace HanoiProgram
{
Class Program
{
Static long count = 0;
Static void move (char x, char y)
{
Console. WriteLine ("{0} ---> {1}", x, y );
}
Static void hanoi (int n, char one, char two, char three)
{
If (n = 1)
{
Count + = 2;
Move (one, two );
Move (two, three );
}
Else
{
Count + = 2;
Hanoi (n-1, one, two, three );
Move (one, two );
Hanoi (n-1, three, two, one );
Move (two, three );
Hanoi (n-1, one, two, three );
}
}
Static void Main (string [] args)
{
Console. WriteLine ("several dishes need to be moved ");
Int n =
Related Article

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.