using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace ConsoleDesktop { class Program { static void Main(string[] args) { HanoiTower hanoi = new HanoiTower(); int sum = hanoi.hanoiTowerSum(3, 'a', 'b', 'c'); Console.WriteLine("总移动次数:{0}", sum); } }
public int hanoiTowerSum(int cnt, char a, char b, char c) { if(cnt == 1) { hanoiMove(a, c); return 1; } else { int sum = 0; sum += hanoiTowerSum(cnt - 1, a, c, b); //步骤1 hanoiMove(a, c); sum += 1; //步骤2 sum += hanoiTowerSum(cnt - 1, b, a, c); //步骤3