summaryrefslogtreecommitdiffstats
path: root/Algorithms/Part-I/5-KdTrees
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-03-27 12:44:43 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-11-15 17:38:45 +0100
commit9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b (patch)
treef773ccedb58a3efc4cd3154867857b73afbd542e /Algorithms/Part-I/5-KdTrees
parent883262806aaa1deacd1e1482e2136f8857e515ed (diff)
downloadcoursera-9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b.zip
coursera-9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b.tar.gz
Algorithms-I : 5-KdTrees: create NearestChampion at KdTree init
Diffstat (limited to 'Algorithms/Part-I/5-KdTrees')
-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;