#include<iostream>
using namespace std;
void hanoi(int n,char one,char two,char three);
int main()
{
int m;
cout<<"输入盘子数:";
cin>>m;
hanoi(m,'A','B','C');
}
void move(char x,char y);
void hanoi(int n,char one,char two,char three)
{
if (n == 1)
{
move(one,three);
}
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void move(char x, char y)
{
cout<<x<<"-->"<<y<<endl;
}
分治算法之汉诺塔
最新推荐文章于 2023-09-13 16:40:16 发布