下面是一部分,还有一部分在下面,直接连起来就可以了
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;
}
|