Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A nearest neighbor to point p; null if the symbol table is empty.
- public Point2D nearest(Point2D p) {
- if (bst.isEmpty()) { return null; }
- double min = Double.POSITIVE_INFINITY;
- Point2D minPoint = new Point2D(0.0, 0.0);
- Queue<Point2D> q = new Queue<Point2D>();
- for (Point2D point: bst.keys()) {
- if (point.equals(p)) { continue; }
- double distance = point.distanceSquaredTo(p);
- if (distance < min) {
- min = distance;
- minPoint = point;
- }
- }
- return minPoint;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement