SHARE
TWEET

Untitled

a guest Apr 25th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top