From 9b8ff0651bc618d2edf2cd7de609f6ec5ccf8e0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 27 Mar 2013 12:44:43 +0100 Subject: Algorithms-I : 5-KdTrees: create NearestChampion at KdTree init --- Algorithms/Part-I/5-KdTrees/KdTree.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; -- cgit v1.1-2-g2b99