#include
void hanoi(int n,char one,char two,char three);
int main(){
hanoi(3,'A','B','C');
}
void hanoi(int n,char one,char two,char three){
/*定义hanoi函数,将n个盘从one座借助two座,移到three座*/
void move(char x,char y);
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){
printf("%c--%c\n",x,y);
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)