汉诺塔

梦想游戏人
目录:
algorithm
  • void hanoi(int n, char a, char b, char c)
  • {
  • if (n > 0)
  • {
  • hanoi(n - 1, a, c, b);
  • cout << a << "->" << b << endl;//move
  • hanoi(n - 1, c, b, a);
  • }
  • }
void hanoi(int n, char a, char b, char c)
{
	if (n > 0)
	{
		hanoi(n - 1, a, c, b);
		cout << a << "->" << b << endl;//move
		hanoi(n - 1, c, b, a);
	}

}
Scroll Up