public class ClosestPair { public final static double INF = java.lang.Double.POSITIVE_INFINITY; public static PointPair closestPair(XYPoint[] points){ XYPoint pointsByX [] = new XYPoint [points.length]; XYPoint pointsByY [] = new XYPoint [points.length]; for (int j = 0; j < points.length; j++) { pointsByX[j] = points[j]; pointsByY[j] = points[j]; } // Ensure sorting precondition for divide-and-conquer algorithm. XComparator xcomp = new XComparator(); YComparator ycomp = new YComparator(); Sort.msort(pointsByX, xcomp); // sort by x-coord Sort.msort(pointsByY, ycomp); // sort by y-coord return findClosestPair(pointsByX, pointsByY); } static PointPair findClosestPair(XYPoint[] ptsByX, XYPoint[] ptsByY){ // This is the recursive procedure -- you take it from here // Just so this will compile without modification, right now it will // return the first two points in ptsByX return new PointPair(ptsByX[0],ptsByX[1]); } }