汉诺塔 游戏代码

来源:百度知道 编辑:UC知道 时间:2024/06/01 16:17:03
各位大虾,有没有汉诺塔游戏的c语言的原代码啊?
在线等啊!
谢谢了!
我只有20分
全奉献给你了!
最好能把程序的
流程图也给我吧!
谢谢了!

简单的汉诺塔演示代码
class Hnt{
int hn[][]=new int[3][10];
public static void main(String args[]){
Hnt hnt=new Hnt();
hnt.init(4,0,2);
}
void init(int num,int from,int to){
for(int i=1;i<=num;i++){
hn[from][i]=num-i+1;
}
hn[from][0]=num;
move(num,from,to);
}
void move(int num,int from,int to){
if(num>1){
move(num-1,from,3-from-to);
if(/*hn[hn[from][0]]==0*/true){
hn[to][++hn[to][0]]=hn[from][hn[from][0]];
hn[from][hn[from][0]--]=0;
print();
}
// System.out.println("Move "+num+" To "+to);
move(num-1,3-from-to,to);
}
else{
if(/*hn[hn[from][0]]==0*/true){
hn[to][++hn[to][0]]=hn[from][hn[from][0]];