`import java.util.LinkedList;  import java.util.Queue;  import java.util.Scanner;   import javax.management.Query;    public class java_debug {            static int queue_node_num=0;//node number      static int son_node=0;//子节点位置      static int closed_node_first=0;//close队列首节点      int node_now=0;//中间变量      static boolean node_exist = false;      static node[] node_name=new node[10000];      static int[][]   initial_element=new int[][]{{0,0,0},{0,0,0},{0,0,0}};       //队列       static Queue<Integer> open= new LinkedList<Integer>();       static Queue<Integer> closed= new LinkedList<Integer>();            static int[][]  target_element= new  int[][]{{1,2,3},{4,5,6},{7,8,0}};                   private static  void  input_function(int[][]  target_input)      {          System.out.println("please input the node!");              for(int j=0;j<=2;j++)                  for(int i=0;i<=2;i++){                      Scanner   target_node=new Scanner(System.in);                      target_input[j][i]=target_node.nextInt();                      }              for(int i=0;i<=2;i++)              for(int ele_node:target_input[i])              {                  if(ele_node>9&&ele_node<0)   {System.out.println("the input is error!");                      }}          }      //比较函数      private static boolean compare_function(int[][] target_node,int[][] son_target)          {   for(int i=0;i<=2;i++)                  for(int j=0;j<=2;j++)                      {  if(target_node[i][j]!=son_target[i][j])                              return false;                      }          return true;                                        }      //初始化该节点      private static void initialize_node(node[] node_name,int queue_node_num,int father_node_num)      {   node_name[queue_node_num+1].node_name=queue_node_num+1;          node_name[queue_node_num+1].father_name=father_node_num;          node_name[queue_node_num+1].location=location(node_name[queue_node_num+1]);          open.offer(node_name[queue_node_num+1].node_name);          }      //0的位置         private  static int location(node node_name)      {int location_coord=0;          for(int j=0;j<=2;j++)          for(int i=0;i<=2;i++)          {              if(node_name.node_element[j][i]==0)                  {location_coord=(j*3+i);              return location_coord;}              }              return 9;          }      //该节点是否已经存在      private static boolean compare_old_node(node[] node_name2,int queue_node_num)          {          while(closed.peek()!=null)          {int i=0;i++;                                     if(i==0) { closed_node_first=closed.poll(); son_node=closed_node_first;}                                      else son_node=closed.poll();              if((son_node==closed_node_first)&&(i!=0)) {closed.offer(son_node);return false;}               if(node_name2[queue_node_num+1].location==node_name2[son_node].location)               node_exist=compare_function(node_name2[queue_node_num+1].node_element,node_name2[son_node].node_element);              if(node_exist==true)                  return true;                  closed.offer(son_node);                        }              return false;                    }      //x,y代表初始坐标  z,w  代表目标坐标  row代表在行上移动还是在列上移动      private   static void  initial_son_node(node[] node_name,int queue_node_num,int father_node_num,int x,int y, int z,int w,boolean row)          {    node_name[queue_node_num+1]=new node( initial_element,queue_node_num+1,father_node_num,0);              node_name[queue_node_num+1].node_element[z][w]=node_name[father_node_num].node_element[x][y];            node_name[queue_node_num+1].node_element[x][y]= node_name[father_node_num].node_element[z][w];            node_name[queue_node_num+1].node_name=queue_node_num+1;            node_name[queue_node_num+1].father_name=father_node_num;           for(int j=0;j<=2;j++)           for(int i=0;i<=2;i++)               {if(row==true) {                   if(j==x&&(i==y||i==w))                       {}                   else                          node_name[queue_node_num+1].node_element[j][i]=node_name[father_node_num].node_element[j][i];}               else                      {if(i==y&&(j==x||j==z))                           {}                       else                              node_name[queue_node_num+1].node_element[j][i]=node_name[father_node_num].node_element[j][i];                              }}                                                  }      private static  int search(node[] node_name,int queue_node_num,int father_name_num,int x,int y,int z,int w,boolean row)      {  boolean   closed_exist_state=true;              initial_son_node(node_name,queue_node_num,father_name_num,x,y,z,w,row);//从父节点得到子节点              closed_exist_state=compare_old_node(node_name,queue_node_num);//该节点是否存在closed节点中              if(closed_exist_state==false)                    {                  initialize_node(node_name,queue_node_num,father_name_num);//对该类就行初始化                  closed_exist_state=compare_function(node_name[queue_node_num].node_element,target_element);                  if(closed_exist_state)  System.out.println("the result has find");//如果与目标节点相同则输出！                  queue_node_num++;}          return queue_node_num;                }                                @SuppressWarnings("null")      public static void main(String[] args) throws Exception      {                               int[][]   begin_element=new  int[][]{{1,2,3},{0,4,5},{7,8,6}};       int j=0;       int father_node_num=0;                 //初始化首节点                           node_name[0]=new node(begin_element,0,0,0);               open.offer(node_name[0].node_name);//压入节点名称               node_name[0].location=location( node_name[0]);                                                ////获取子节点               while(open.peek()!=null) { //循环                                     j++;                   if(j>500)System.out.println("the program is not find the result!!");                   System.out.println(j);                   father_node_num=open.poll();                   if(compare_function(target_element,node_name[father_node_num].node_element))                    { System.out.println("success!");                      while(node_name[father_node_num].node_name!=0)                      {                          for(int i=0;i<=2;i++)                          {for(int j1=0;j1<=2;j1++)                          System.out.print(node_name[father_node_num].node_element[i][j1]+" ");                          System.out.println( );                            }                          System.out.println(node_name[father_node_num].node_name);                          father_node_num=node_name[father_node_num].father_name;                                                                                                    }                                                                                               break;}                    //queue_node_num=father_node_num;                   closed.offer( father_node_num);//压入closed队列                   son_node=node_name[father_node_num].location;                   switch(son_node){                    case 0:                       /* node_name[queue_node_num+1].node_element[0][1]=node_name[father_node_num].node_element[0][0];                       node_name[queue_node_num+1].node_element[0][0]= node_name[father_node_num].node_element[0][1];                       node_name[queue_node_num+1].node_name=queue_node_num+1;                       node_name[queue_node_num+1].father_name=father_node_num;                      for(int j=0;j<=2;j++)                       for(int i=0;i<=2;i++)                      {    if(j==0&&(i==0||i==1))                                   {}                              else                                      node_name[queue_node_num+1].node_element[j][i]=node_name[queue_node_num].node_element[j][i];                      }*/                       queue_node_num= search(node_name,queue_node_num,father_node_num,0,0,0,1,true);                        queue_node_num= search(node_name,queue_node_num,father_node_num,0,0,1,0,false);                       break;                   case 1:                       queue_node_num= search(node_name,queue_node_num,father_node_num,0,1,0,0,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,0,1,0,2,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,0,1,1,1,false);                          break;                   case 2:                       queue_node_num=search(node_name,queue_node_num,father_node_num,0,2,0,1,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,0,2,1,2,false);                          break;                   case 3:                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,0,0,0,false);                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,0,1,1,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,0,2,0,false);                       break;                   case 4:                        queue_node_num= search(node_name,queue_node_num,father_node_num,1,1,0,1,false);                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,1,1,0,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,1,1,2,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,1,2,1,false);                       break;                   case 5:                        queue_node_num=search(node_name,queue_node_num,father_node_num,1,2,0,2,false);                       queue_node_num=    search(node_name,queue_node_num,father_node_num,1,2,2,2,false);                       queue_node_num=search(node_name,queue_node_num,father_node_num,1,2,1,1,true);                       break;                   case 6:                       queue_node_num=search(node_name,queue_node_num,father_node_num,2,0,1,0,false);                       queue_node_num=search(node_name,queue_node_num,father_node_num,2,0,2,1,true);                          break;                   case 7:                       queue_node_num= search(node_name,queue_node_num,father_node_num,2,1,2,0,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,2,1,2,2,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,2,1,1,1,false);                       break;                   case 8:                       queue_node_num=search(node_name,queue_node_num,father_node_num,2,2,2,2,true);                       queue_node_num=search(node_name,queue_node_num,father_node_num,2,2,1,2,false);                       break;                   default:   System.out.println("the location is error!");                   } }                 }}  `

` public class node {           int[][]  node_element= new  int[3][3];          int node_name;          int father_name;          int location;      node(int[][] node_element,int node_name,int father,int location){          this.father_name=father;          this.node_name=node_name;          for(int i=0;i<=2;i++)              for(int j=0;j<=2;j++)                  this.node_element[i][j]=node_element[i][j];          this.location=location;                }   }  `