资源简介

最近复习数据结构,就写了2个小程序,能够清晰的展示路径搜索的过程,以及移动碟子的过程

资源截图

代码片段和文件信息

package 汉诺塔;

public class Hanoi 
{
public static void main(String[] args)
{
Hanoi h=new Hanoi(5);
h.hanoi(5 “0“ “1“ “2“);
}
Stack tower[];
Show show;
Hanoi(int n)
{
show=new Show();
tower=new Stack[3];
tower[0]=new Stack(n);
tower[1]=new Stack(n);
tower[2]=new Stack(n);
for(int i=n-1;i>=0;i--)
{
tower[0].push(i+1);
}
}
public void hanoi(int n String tower1 String tower2 String tower3) 
{
if (n == 1) 
{
moveDish(n tower1 tower3);

else
{
hanoi(n - 1 tower1 tower3 tower2);
moveDish(n tower1 tower3);
hanoi(n - 1 tower2 tower1 tower3);
}
}

private void moveDish(int n String tower1 String tower3) 
{
try 
{
Thread.sleep(1000);

catch (InterruptedException e) 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        232  2009-09-03 21:20  汉诺塔\.classpath

     文件        385  2009-09-03 21:20  汉诺塔\.project

     文件       2106  2009-09-04 08:45  汉诺塔\bin\汉诺塔\Hanoi.class

     文件       2127  2009-09-04 08:45  汉诺塔\bin\汉诺塔\Show.class

     文件        796  2009-09-04 08:45  汉诺塔\bin\汉诺塔\Stack.class

     文件        646  2009-09-02 16:22  汉诺塔\dish.jpg

     文件       1028  2009-09-04 08:21  汉诺塔\src\汉诺塔\Hanoi.java

     文件       1271  2009-09-04 08:13  汉诺塔\src\汉诺塔\Show.java

     文件        460  2009-09-03 21:59  汉诺塔\src\汉诺塔\Stack.java

     文件        232  2009-09-02 08:50  迷宫\.classpath

     文件        382  2009-09-02 08:50  迷宫\.project

     文件       1406  2009-09-04 08:45  迷宫\bin\maze\Control.class

     文件       2207  2009-09-04 08:45  迷宫\bin\maze\Map.class

     文件       2289  2009-09-04 08:45  迷宫\bin\maze\Show.class

     文件        558  2009-09-04 08:45  迷宫\bin\maze\Start.class

     文件          0  2009-09-02 11:38  迷宫\bin\New Bitmap Image.bmp

     文件        646  2009-09-02 16:22  迷宫\blank.jpg

     文件        646  2009-09-02 16:22  迷宫\block.jpg

     文件        646  2009-09-02 16:23  迷宫\goal.jpg

     文件        108  2009-09-02 15:47  迷宫\map.txt

     文件        643  2009-09-02 16:23  迷宫\people.jpg

     文件        647  2009-09-02 16:23  迷宫\road.jpg

     文件       1425  2009-09-02 15:06  迷宫\src\maze\Control.java

     文件       1486  2009-09-02 16:26  迷宫\src\maze\Map.java

     文件       1752  2009-09-02 16:20  迷宫\src\maze\Show.java

     文件        191  2009-09-02 14:50  迷宫\src\maze\Start.java

     目录          0  2009-09-04 08:45  汉诺塔\bin\汉诺塔

     目录          0  2009-09-03 21:43  汉诺塔\src\汉诺塔

     目录          0  2009-09-04 08:45  迷宫\bin\maze

     目录          0  2009-09-02 15:48  迷宫\src\maze

............此处省略9个文件信息

评论

共有 条评论