Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1. public static Node DigFreakingSearch(Node start, Node goal){
  2.         Stack<Node> stack = new Stack<>();
  3.         HashSet<Node> discovered = new HashSet<>();
  4.  
  5.         stack.add(start);
  6.         discovered.add(start);
  7.  
  8.         while(!stack.isEmpty()){
  9.             Node v = stack.pop();
  10.             discovered.add(v);
  11.             if(v.equals(goal)){
  12.                 return v;
  13.             }
  14.             for(Node w : v.getNeighbors()){
  15.                 if(!discovered.contains(w)){
  16.                     w.setParent(v);
  17.                     stack.add(w);
  18.                 }
  19.             }
  20.         }
  21.  
  22.         return null;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement