#include <iostream>
using namespace std;
void TowersOfHanoi(int n, int x, int y, int z)
{ //把n 个碟子从塔x 移动到塔y,可借助于塔z
if (n > 0) {
TowersOfHanoi(n-1, x,z,y);
cout << "Move top disk from tower " << x <<" to top of tower " << y << endl;
TowersOfHanoi(n-1, z, y, x);}
}
int main()
{
TowersOfHanoi(10,1,2,3);
return 0;
}
递归解决汉诺塔问题C++
最新推荐文章于 2024-08-02 12:16:33 发布