#include <iostream>
using namespace std;
void hano(int n, char from, char to, char temp);
int main(int argc, char *argv[])
{
hano(3, 'A', 'C', 'B');
return 0;
}
void hano(int n, char from, char to, char temp) {
if (n == 1)
cout << from << "---->" << to << endl;
else {
hano(n - 1, from, temp, to);
hano(1, from, to, temp);
hano(n - 1, temp, to, from);
}
}
汉诺塔
最新推荐文章于 2022-09-05 16:01:58 发布