Remove unnecessary code (#4141)

This commit is contained in:
Saurabh Rahate
2023-04-03 20:05:59 +05:30
committed by GitHub
parent 805f09850c
commit ad72c28d91
64 changed files with 125 additions and 322 deletions

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Arrays;
import java.util.Random;
@ -86,23 +84,15 @@ class BinarySearch implements SearchAlgorithm {
BinarySearch search = new BinarySearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
System.out.println(
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
}
}

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Arrays;
import java.util.Random;
@ -29,24 +27,16 @@ class ExponentialSearch implements SearchAlgorithm {
ExponentialSearch search = new ExponentialSearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
System.out.println(
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
}
@Override

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import java.util.Arrays;
import java.util.Random;
import java.util.stream.IntStream;
@ -67,28 +65,20 @@ class InterpolationSearch {
.toArray();
// the element that should be found
Integer shouldBeFound = integers[r.nextInt(size - 1)];
int shouldBeFound = integers[r.nextInt(size - 1)];
InterpolationSearch search = new InterpolationSearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
String.format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
System.out.println(
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
}
}

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Arrays;
import java.util.Random;
@ -72,23 +70,15 @@ public final class IterativeBinarySearch implements SearchAlgorithm {
IterativeBinarySearch search = new IterativeBinarySearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
String.format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
System.out.println(
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
}
}

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Arrays;
import java.util.Random;
@ -70,23 +68,15 @@ public class IterativeTernarySearch implements SearchAlgorithm {
IterativeTernarySearch search = new IterativeTernarySearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
System.out.println(
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
}
}

View File

@ -53,14 +53,12 @@ public class LinearSearch implements SearchAlgorithm {
LinearSearch search = new LinearSearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
String.format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
}
}

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
@ -48,24 +46,16 @@ class LowerBound implements SearchAlgorithm {
LowerBound search = new LowerBound();
int atIndex = search.find(integers, val);
System.out.println(
format(
"Val: %d. Lower Bound Found %d at index %d. An array length %d",
System.out.printf(
"Val: %d. Lower Bound Found %d at index %d. An array length %d%n",
val,
integers[atIndex],
atIndex,
size
)
);
boolean toCheck = integers[atIndex] >= val || integers[size - 1] < val;
System.out.println(
format(
"Lower Bound found at an index: %d. Is greater or max element: %b",
atIndex,
toCheck
)
);
System.out.printf("Lower Bound found at an index: %d. Is greater or max element: %b%n", atIndex, toCheck);
}
/**

View File

@ -187,13 +187,11 @@ public class MonteCarloTreeSearch {
System.out.println("N.\tScore\t\tVisits");
for (int i = 0; i < rootNode.childNodes.size(); i++) {
System.out.println(
String.format(
"%02d\t%d\t\t%d",
System.out.printf(
"%02d\t%d\t\t%d%n",
i + 1,
rootNode.childNodes.get(i).score,
rootNode.childNodes.get(i).visitCount
)
);
}
}

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Arrays;
import java.util.Random;
@ -89,23 +87,15 @@ public class TernarySearch implements SearchAlgorithm {
TernarySearch search = new TernarySearch();
int atIndex = search.find(integers, shouldBeFound);
System.out.println(
format(
"Should be found: %d. Found %d at index %d. An array length %d",
System.out.printf(
"Should be found: %d. Found %d at index %d. An array length %d%n",
shouldBeFound,
integers[atIndex],
atIndex,
size
)
);
int toCheck = Arrays.binarySearch(integers, shouldBeFound);
System.out.println(
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
System.out.printf("Found by system method at an index: %d. Is equal: %b%n", toCheck, toCheck == atIndex);
}
}

View File

@ -1,7 +1,5 @@
package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
@ -48,24 +46,16 @@ class UpperBound implements SearchAlgorithm {
UpperBound search = new UpperBound();
int atIndex = search.find(integers, val);
System.out.println(
format(
"Val: %d. Upper Bound Found %d at index %d. An array length %d",
System.out.printf(
"Val: %d. Upper Bound Found %d at index %d. An array length %d%n",
val,
integers[atIndex],
atIndex,
size
)
);
boolean toCheck = integers[atIndex] > val || integers[size - 1] < val;
System.out.println(
format(
"Upper Bound found at an index: %d. Is greater or max element: %b",
atIndex,
toCheck
)
);
System.out.printf("Upper Bound found at an index: %d. Is greater or max element: %b%n", atIndex, toCheck);
}
/**