mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-26 22:14:08 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -83,7 +83,6 @@ public final class ClosestPair {
|
||||
* @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
|
||||
@ -111,7 +110,6 @@ public final class ClosestPair {
|
||||
* @return pivot index
|
||||
*/
|
||||
public int yPartition(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
|
||||
@ -137,8 +135,11 @@ public final class ClosestPair {
|
||||
* @param first (IN Parameter) first point <br>
|
||||
* @param last (IN Parameter) last point <br>
|
||||
*/
|
||||
public void xQuickSort(final Location[] a, final int first, final int last) {
|
||||
|
||||
public void xQuickSort(
|
||||
final Location[] a,
|
||||
final int first,
|
||||
final int last
|
||||
) {
|
||||
if (first < last) {
|
||||
int q = xPartition(a, first, last); // pivot
|
||||
xQuickSort(a, first, q - 1); // Left
|
||||
@ -153,8 +154,11 @@ public final class ClosestPair {
|
||||
* @param first (IN Parameter) first point <br>
|
||||
* @param last (IN Parameter) last point <br>
|
||||
*/
|
||||
public void yQuickSort(final Location[] a, final int first, final int last) {
|
||||
|
||||
public void yQuickSort(
|
||||
final Location[] a,
|
||||
final int first,
|
||||
final int last
|
||||
) {
|
||||
if (first < last) {
|
||||
int q = yPartition(a, first, last); // pivot
|
||||
yQuickSort(a, first, q - 1); // Left
|
||||
@ -170,7 +174,6 @@ public final class ClosestPair {
|
||||
* @return minimum distance <br>
|
||||
*/
|
||||
public double closestPair(final Location[] a, final int indexNum) {
|
||||
|
||||
Location[] divideArray = new Location[indexNum];
|
||||
System.arraycopy(a, 0, divideArray, 0, indexNum); // Copy previous array
|
||||
int divideX = indexNum / 2; // Intermediate value for divide
|
||||
@ -183,7 +186,13 @@ public final class ClosestPair {
|
||||
// divide-left array
|
||||
System.arraycopy(divideArray, 0, leftArray, 0, divideX);
|
||||
// divide-right array
|
||||
System.arraycopy(divideArray, divideX, rightArray, 0, indexNum - divideX);
|
||||
System.arraycopy(
|
||||
divideArray,
|
||||
divideX,
|
||||
rightArray,
|
||||
0,
|
||||
indexNum - divideX
|
||||
);
|
||||
|
||||
double minLeftArea; // Minimum length of left array
|
||||
double minRightArea; // Minimum length of right array
|
||||
@ -257,7 +266,6 @@ public final class ClosestPair {
|
||||
* @return <br>
|
||||
*/
|
||||
public double bruteForce(final Location[] arrayParam) {
|
||||
|
||||
double minValue = Double.MAX_VALUE; // minimum distance
|
||||
double length;
|
||||
double xGap; // Difference between x coordinates
|
||||
@ -312,7 +320,6 @@ public final class ClosestPair {
|
||||
* @param args (IN Parameter) <br>
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
|
||||
// Input data consists of one x-coordinate and one y-coordinate
|
||||
ClosestPair cp = new ClosestPair(12);
|
||||
cp.array[0] = cp.buildLocation(2, 3);
|
||||
|
Reference in New Issue
Block a user