/**
*汉诺塔问题
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[]){
void hanoi(int n,char one,char two,char three);
int n;
printf("Please input the number of diskes:");
scanf("%d",&n);
printf("The step to moving %d diskes:\n",n);
hanoi(n,'A','B','C');
}
//将n个盘子从one座借助two座,移到three座
void hanoi(int n,char one,char two,char 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);
}
汉诺塔问题
最新推荐文章于 2022-02-25 18:19:43 发布