summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Algorithms/Part-I/5-KdTrees/KdTree.java5
1 files changed, 4 insertions, 1 deletions
diff --git a/Algorithms/Part-I/5-KdTrees/KdTree.java b/Algorithms/Part-I/5-KdTrees/KdTree.java
index e11a769..6a13d16 100644
--- a/Algorithms/Part-I/5-KdTrees/KdTree.java
+++ b/Algorithms/Part-I/5-KdTrees/KdTree.java
@@ -9,6 +9,7 @@ public class KdTree
private Node root;
private int size;
+ NearestChampion ncp;
private class Node {
private Point2D p;
@@ -35,6 +36,7 @@ public class KdTree
{
size = 0;
root = null;
+ ncp = new NearestChampion(null, Double.MAX_VALUE);
}
// is the tree empty?
@@ -199,7 +201,8 @@ public class KdTree
{
if ((p == null) || (root == null)) return null;
- NearestChampion ncp = new NearestChampion(null, Double.MAX_VALUE);
+ ncp.p = null;
+ ncp.d = Double.MAX_VALUE;
nearest(root, p, ncp, true);
return ncp.p;