经典递归应用--汉诺塔(C#语言版)
using System;
using System.Collections.Generic;
using System.Text;
namespace Hanoi
{
class Program
{
static void Main(string[] args)
{
int li_disk_total;
System.Console.Write("Please input disk total:");
int.TryParse(System.Console.ReadLine(),out li_disk_total);
hanoi(li_disk_total, 'a', 'b', 'c');
System.Console.WriteLine("Move success");
System.Console.ReadLine();
}
public static void hanoi(int n,char a,char b,char c)
{
if (n == 1)
move(n, a, c);
else
{
hanoi(n - 1, a, c, b);
move(n, a, c);
hanoi(n - 1, b, a, c);
}
}
public static void move(int n,char x,char y)
{
System.Console.WriteLine("Disk " + n.ToString() + " from " + x + " move to " + y);
System.Collections.
}
}
}