Java 链表节点值
作者:互联网
public class AStar
{
private List<Node> openList;
private List<Node> closeList;
private int startX,startY,endX,endY;
public AStar(){
openList=new ArrayList<Node>();
closeList=new ArrayList<Node>();
}
/*调用search方法*/
public static void main(String[] args) {
int[][] map = new int[][] {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1 }
};
Astar astar=new Astar();
astar.search(0,0, 5, 9);
}
/*判断是否到达目标*/
public int search(int startX,int startY,int endX,int endY){
if((index=contain(openList,end.x,end.y))!=-1){//如果不等于-1就到终点
int count=-1;
Node nowNode=openList.get(index);
Node getNode=nowNode;//不太明白之处
while(getNode.father!=null)
{
getNode=getNode.father;
count++;
}
}
/*如果包含则返回索引,否则返回-1*/
private int contain(List<Node> nodes,int x,int y){
Node node=null;
for(int i=0;i<nodes.size();i++)
{
node=nodes.get(i);
if(node.x==x&&node.y==y)
return i;
}
return -1;
}
/*节点*/
public Node(int x,int y,Node father){
this.x=x;
this.y=y;
this.father=father;
}
}
标签:Node,Java,int,father,private,public,链表,openList,节点 来源: https://blog.csdn.net/m0_61105636/article/details/120789367