JAVA写的骑士游历,怎么输不出结果

[复制链接]
查看11 | 回复1 | 2010-5-18 15:42:19 | 显示全部楼层 |阅读模式
下面是一部分,还有一部分在下面,直接连起来就可以了
package pk;//引用的包,用于栈操作
class Node
{public T data;
public Node next=null;
public Node(){};
public Node(T data)
{this.data=data;
}
public Node(T data,Node next)
{this.data=data;
this.next=next;
}
}
public class LinkedList{
public Node top=new Node();
public boolean isEmpty()
{return top.next==null;}
public void push(T x)
{top=new Node(x,top);
}
public T pop()
{if(!isEmpty())
{T x=top.data;
top=top.next;
return x;
}
else return null;
}
public T get()
{if(!isEmpty())
{T x=top.data;
return x;
}
else return null;
}
public static void main(String[] args)
{}
}
package horseTravel;
import java.util.Arrays;
import pk.*;//主程序,走下一步之前,将当前位置入栈
class Position
{public int x;
public int y;
public int i=-1;//记录数组中当前元素序列
public TryStep[] list=new TryStep[8];
public Position(){}
public Position(int x,int y)
{this.x=x;
this.y=y;
}
public Position(int x,int y,int i,TryStep[] list)
{this.x=x;
this.y=y;
this.i=i;
this.list=list;
}
}
class TryStep implements Comparable[Tr]
{ public int direction;
public int step; //某个方向上下一步可走步数
public TryStep(int direction,int step)
{this.direction=direction;
this.step=step;
}
public int compareTo(TryStep t)
{

if(this.stept.step)
return 1;
return 0;
}
}
public class HorseTravel {
private int thenStep;
private int[][] xy=new int[8][8];
private LinkedList stack=new LinkedList();
private void fill() //将每个格子设为0
{for(int i=0;i=0&&x=0&&y=0&&s.x=0&&s.y<=7&&xy[s.x][s.y]==0)

return true;

else return false;

}

回复

使用道具 举报

千问 | 2010-5-18 15:42:19 | 显示全部楼层
public Position goaStep(Position p,int direction)//从P位置向前走一步
{int x=p.x;
int y=p.y;
switch(direction)
{case 1:x+=1;
y-=2;
break;
case 2:x+=2;
y-=1;
break;
case 3:x+=2;
y+=1;
break;
case 4:x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行