Java教程

Java 链表节点值

本文主要是介绍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;
  }

}
 

这篇关于Java 链表节点值的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!