百度空间 | 百度首页 
 
查看文章
 
汉诺塔Hanoi
2008-07-22 16:30
public static void Hanoi(int n, string a, string b, string c)
        {
            if (n == 1)
            {
                //move the one dish of a to c
                Console.WriteLine("{0} -> {1}", a, c);
            }
            else if (n > 1)
            {
                //move n-1 dishes of a to b
                Hanoi(n - 1, a, c, b);
                //move the bigest dish of a to c
                Console.WriteLine("{0} -> {1}", a, c);
                //move the n-1 dishes of c to c
                Hanoi(n - 1, b, a, c);
            }
        }

类别:c#版数据结构 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu