【求助】递归~HANOI塔~求讲解~
#include <iostream>using namespace std;
int c;
void print(char x, int n, char y)
{
cout<<"第"<<n<<"个盘子"<<"从"<<x<<"移动到"<< y<< endl;
}
void move(int n, char A, char B, char C)
{
if (n == 1)
print(A, 1, C);
else
{
move(n - 1, A, C, B);
print(A, n, C);
move(n - 1, B, A, C);
}
}
void main()
{
int n;
cout << "几个盘子: " ;
cin >> n;
move(n, 'A', 'B', 'C');
}