汉诺塔问题

#include<iostream>
using namespace std;
void move(char a, char b)
{
cout << a << "-->" << b << endl;
}
void hanoi(int n, char a, char b, char c)
{
if (n == 1)
{
move(a, c);
}
else
{
hanoi(n - 1, a, c, b);
move(a, c);
hanoi(n - 1, b, a, c);
}
}
int main()
{
int m;
cin >> m;
hanoi(m, 'A', 'B', 'C');
system("pause");
return 0;
}
阅读更多

没有更多推荐了,返回首页