#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++
猜你喜欢
转载自blog.csdn.net/jirryzhang/article/details/79173446
今日推荐
周排行