int hano(int n, char S, char D, char temp)
{
// S: 起始位置
// D: 目标位置
// temp: 临时位置
if(n < 1){
return 0;
}
else if(1 == n){
cout<< "Move panel " << n << " from " << S << " to " << D << endl;
}
else{
hano(n-1, S, temp, D);
cout<< "Move panel " << n << " from " << S << " to " << D << endl;
hano(n-1, temp, D, S);
}
return 1;
}
汉诺塔
最新推荐文章于 2025-05-03 15:21:04 发布