Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement