//将n个盘子从A通过B移到C
void Hannoi(int n, char A, char B, char C)
{
if(n == 1){
cout<<A<<"->"<<C<<endl;
}
else if(n == 2){
cout<<A<<"->"<<B<<endl;
cout<<A<<"->"<<C<<endl;
cout<<B<<"->"<<C<<endl;
}
else{
Hannoi(n - 1, A, C, B);
Hannoi(1, A, B, C);
Hannoi(n - 1, B, A, C);
}
}
原理参见 屈婉玲老师 算法设计与分析 ORZ