SHARE
TWEET

Untitled

a guest Jul 17th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // A nearest neighbor to point p; null if the symbol table is empty.
  2.     public Point2D nearest(Point2D p) {
  3.         if (bst.isEmpty()) { return null; }
  4.  
  5.         double min = Double.POSITIVE_INFINITY;
  6.        
  7.         Point2D minPoint = new Point2D(0.0, 0.0);
  8.        
  9.         Queue<Point2D> q = new Queue<Point2D>();
  10.        
  11.         for (Point2D point: bst.keys()) {
  12.             if (point.equals(p)) { continue; }
  13.            
  14.            
  15.             double distance = point.distanceSquaredTo(p);
  16.            
  17.             if (distance < min) {
  18.                 min = distance;
  19.                 minPoint = point;
  20.             }
  21.         }
  22.        
  23.         return minPoint;
  24.     }
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