Question: Anyone, please help me fix the error in my code? package closestpair; import java.util.*; public class ClosestPair { public static class Point { public final

Anyone, please help me fix the error in my code?

package closestpair;

import java.util.*;

public class ClosestPair {

public static class Point { public final double x; public final double y; public Point(double x,double y) { this.x=x; this.y=y; } } public static class Pair { public Point Point1=null,point2=null; public double distance=0.0; Pair(Point point1,Point point2) { this.point1=point1; this.point2=point2; calculateDistance(); } public void update(Point point1,Point point2,double distance) { this.point1=point1; this.point2=point2; this.distance=distance; } public void calculateDistance() { this.distance=distance(point1,point2); } public String toString() { return "("+point1+","+point2+"):"=distance; } } public static double distance(Point p1,Point p2) { double xdist=p2.x-p1.x; double ydist=p2.y-p1.y; return Math.hypot(xdist, ydist); } public static void CompareY(Listpoints) { Collections.sort(points,new Comparator() { public int compare(Point point1, Point point2) { if(point1.ypoint1.y) return 1; return 0; } }); } public static void CompareX(Listpoints) { Collections.sort(points,new Comparator() { public int compare(Point point1,Point point2) { if(point1.xpoint2.x) return 1; return 0; } }); } public static Pair divideAndConquer(Listpoints) { ListpointsSortedByX=new ArrayList(points); CompareX(pointsSortedByX); ListpointsSortedByY=new ArrayList(points); CompareY(pointsSortedByY); return divideAndConquer(pointsSortedByX,pointsSortedByY); } private static Pair divideAndConquer(ListpointsSortedByX, ListpointsSortedByY) { int numPoints=pointsSortedByX.size(); int dividingIndex=numPoints>>>1; ListleftOfCenter=pointsSortedByX.subList(0, dividingIndex); ListrightOfCenter=pointsSortedByX.subList(dividingIndex,numPoints); ListtempList=new ArrayList(leftOfCenter); CompareY(tempList); Pair closestPair=divideAndConquer(leftOfCenter,tempList); tempList.clear(); tempList.addAll(rigthOfCenter); CompareY(tempList); Pair closestPairRight=divideAndConquer(rightOfCenter, tempList); if(closestPairRight.distance=shortestDistance) break; double distance=distance(point1,point2); if(distance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!