Skip to content

Commit 1104b83

Browse files
committed
Fix recursive call
1 parent 5f5b71b commit 1104b83

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/main/java/com/packt/datastructuresandalg/lesson4/points/ClosestPairOfPoints.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ PointPair bestWithStrip(List<Point> points, PointPair bestSoFar) {
4545
Collections.sort(sortedPoints, (o1, o2) -> Integer.signum(o1.y - o2.y));
4646

4747
for (int i = 0; i < points.size(); i++) {
48-
for (int j = i + 1; j < points.size() && (points.get(j).y - points.get(i).y) < best.distance(); j++) {
48+
for (int j = i + 1; j < points.size() &&
49+
(points.get(j).y - points.get(i).y) < best.distance(); j++) {
4950
PointPair candidate = new PointPair(points.get(i), points.get(j));
5051
if (candidate.distance() < best.distance())
5152
best = candidate;
@@ -63,8 +64,8 @@ PointPair divideAndConquerAux(List<Point> points) {
6364
int mid = N / 2;
6465
Point midPoint = points.get(mid);
6566

66-
PointPair bl = divideAndConquer(points.subList(0, mid));
67-
PointPair br = divideAndConquer(points.subList(mid, N));
67+
PointPair bl = divideAndConquerAux(points.subList(0, mid));
68+
PointPair br = divideAndConquerAux(points.subList(mid, N));
6869

6970
PointPair bestSoFar = bl;
7071
if (br.distance() < bl.distance())

0 commit comments

Comments
 (0)