mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-24 04:54:21 +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);
|
||||
|
@ -45,7 +45,6 @@ public class SkylineAlgorithm {
|
||||
* @see Point
|
||||
*/
|
||||
public ArrayList<Point> produceSubSkyLines(ArrayList<Point> list) {
|
||||
|
||||
// part where function exits flashback
|
||||
int size = list.size();
|
||||
if (size == 1) {
|
||||
@ -93,11 +92,16 @@ public class SkylineAlgorithm {
|
||||
* @param right the skyline of the right part of points
|
||||
* @return left the final skyline
|
||||
*/
|
||||
public ArrayList<Point> produceFinalSkyLine(ArrayList<Point> left, ArrayList<Point> right) {
|
||||
|
||||
public ArrayList<Point> produceFinalSkyLine(
|
||||
ArrayList<Point> left,
|
||||
ArrayList<Point> right
|
||||
) {
|
||||
// dominated points of ArrayList left are removed
|
||||
for (int i = 0; i < left.size() - 1; i++) {
|
||||
if (left.get(i).x == left.get(i + 1).x && left.get(i).y > left.get(i + 1).y) {
|
||||
if (
|
||||
left.get(i).x == left.get(i + 1).x &&
|
||||
left.get(i).y > left.get(i + 1).y
|
||||
) {
|
||||
left.remove(i);
|
||||
i--;
|
||||
}
|
||||
@ -168,7 +172,10 @@ public class SkylineAlgorithm {
|
||||
*/
|
||||
public boolean dominates(Point p1) {
|
||||
// checks if p1 is dominated
|
||||
return (this.x < p1.x && this.y <= p1.y) || (this.x <= p1.x && this.y < p1.y);
|
||||
return (
|
||||
(this.x < p1.x && this.y <= p1.y) ||
|
||||
(this.x <= p1.x && this.y < p1.y)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,7 @@ public class StrassenMatrixMultiplication {
|
||||
|
||||
// Using Formulas as described in algorithm
|
||||
// M1:=(A1+A3)×(B1+B2)
|
||||
int[][] M1
|
||||
= multiply(add(A11, A22), add(B11, B22));
|
||||
int[][] M1 = multiply(add(A11, A22), add(B11, B22));
|
||||
|
||||
// M2:=(A2+A4)×(B3+B4)
|
||||
int[][] M2 = multiply(add(A21, A22), B11);
|
||||
@ -55,12 +54,10 @@ public class StrassenMatrixMultiplication {
|
||||
int[][] M5 = multiply(add(A11, A12), B22);
|
||||
|
||||
// M6:=(A1+A2)×(B4)
|
||||
int[][] M6
|
||||
= multiply(sub(A21, A11), add(B11, B12));
|
||||
int[][] M6 = multiply(sub(A21, A11), add(B11, B12));
|
||||
|
||||
// M7:=A4×(B3−B1)
|
||||
int[][] M7
|
||||
= multiply(sub(A12, A22), add(B21, B22));
|
||||
int[][] M7 = multiply(sub(A12, A22), add(B21, B22));
|
||||
|
||||
// P:=M2+M3−M6−M7
|
||||
int[][] C11 = add(sub(add(M1, M4), M5), M7);
|
||||
@ -102,7 +99,6 @@ public class StrassenMatrixMultiplication {
|
||||
// Method 3
|
||||
// Function to add two matrices
|
||||
public int[][] add(int[][] A, int[][] B) {
|
||||
|
||||
int n = A.length;
|
||||
|
||||
int[][] C = new int[n][n];
|
||||
@ -141,7 +137,9 @@ public class StrassenMatrixMultiplication {
|
||||
// Method 5
|
||||
// Main driver method
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Strassen Multiplication Algorithm Implementation For Matrix Multiplication :\n");
|
||||
System.out.println(
|
||||
"Strassen Multiplication Algorithm Implementation For Matrix Multiplication :\n"
|
||||
);
|
||||
|
||||
StrassenMatrixMultiplication s = new StrassenMatrixMultiplication();
|
||||
|
||||
@ -151,17 +149,21 @@ public class StrassenMatrixMultiplication {
|
||||
|
||||
// Matrix A
|
||||
// Custom input to matrix
|
||||
int[][] A = {{1, 2, 5, 4},
|
||||
{9, 3, 0, 6},
|
||||
{4, 6, 3, 1},
|
||||
{0, 2, 0, 6}};
|
||||
int[][] A = {
|
||||
{ 1, 2, 5, 4 },
|
||||
{ 9, 3, 0, 6 },
|
||||
{ 4, 6, 3, 1 },
|
||||
{ 0, 2, 0, 6 },
|
||||
};
|
||||
|
||||
// Matrix B
|
||||
// Custom input to matrix
|
||||
int[][] B = {{1, 0, 4, 1},
|
||||
{1, 2, 0, 2},
|
||||
{0, 3, 1, 3},
|
||||
{1, 8, 1, 2}};
|
||||
int[][] B = {
|
||||
{ 1, 0, 4, 1 },
|
||||
{ 1, 2, 0, 2 },
|
||||
{ 0, 3, 1, 3 },
|
||||
{ 1, 8, 1, 2 },
|
||||
};
|
||||
|
||||
// Matrix C computations
|
||||
// Matrix C calling method to get Result
|
||||
|
Reference in New Issue
Block a user