[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/primary-code-test/Java/master/divideconquer/ClosestPair.java [Back]  [Original]

package divideconquer; /** * For a set of points in a coordinates system (10000 maximum), ClosestPair class calculates the two * closest points. * * @author: anonymous * @author: Marisa Afuera */ public final class ClosestPair { /** Number of points */ int numberPoints = 0; /** Input data, maximum 10000. */ private Location[] array; /** Minimum point coordinate. */ Location point1 = null; /** Minimum point coordinate. */ Location point2 = null; /** Minimum point length. */ private static double minNum = Double.MAX_VALUE; public static void setMinNum(double minNum) { ClosestPair.minNum = minNum; } public static void setSecondCount(int secondCount) { ClosestPair.secondCount = secondCount; } /** secondCount */ private static int secondCount = 0; /** Constructor. */ ClosestPair(int points) { numberPoints = points; array = new Location[numberPoints]; } /** Location class is an auxiliary type to keep points coordinates. */ public static class Location { double x = 0; double y = 0; /** * @param xpar (IN Parameter) x coordinate
* @param ypar (IN Parameter) y coordinate
*/ Location(final double xpar, final double ypar) { // Save x, y coordinates this.x = xpar; this.y = ypar; } } public Location[] createLocation(int numberValues) { return new Location[numberValues]; } public Location buildLocation(double x, double y) { return new Location(x, y); } /** * xPartition function: arrange x-axis. * * @param a (IN Parameter) array of points
* @param first (IN Parameter) first point
* @param last (IN Parameter) last point
* @return pivot index */ public int xPartition(final Location[] a, final int first, final int last) { Location pivot = a[last]; // pivot int i = first - 1; Location temp; // Temporarily store value for position transformation for (int j = first; j
Web Proxy Viewer  |  New URL  |  Original Page