diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-03-27 12:44:43 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2013-11-15 17:38:45 +0100 |
commit | 9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b (patch) | |
tree | f773ccedb58a3efc4cd3154867857b73afbd542e | |
parent | 883262806aaa1deacd1e1482e2136f8857e515ed (diff) | |
download | coursera-9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b.zip coursera-9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b.tar.gz |
Algorithms-I : 5-KdTrees: create NearestChampion at KdTree init
-rw-r--r-- | Algorithms/Part-I/5-KdTrees/KdTree.java | 5 |
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; |