mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-22 03:24:57 +08:00
docs: update the whole repository
* fix some bugs * delete duplicate files * format code
This commit is contained in:
@ -2,7 +2,7 @@ package Searches;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static java.lang.String.format;
|
||||
@ -38,7 +38,7 @@ class BinarySearch implements SearchAlgorithm {
|
||||
* @return index of the element
|
||||
*/
|
||||
@Override
|
||||
public <T extends Comparable<T>> int find(T array[], T key) {
|
||||
public <T extends Comparable<T>> int find(T[] array, T key) {
|
||||
return search(array, key, 0, array.length);
|
||||
}
|
||||
|
||||
@ -77,7 +77,8 @@ class BinarySearch implements SearchAlgorithm {
|
||||
int size = 100;
|
||||
int maxElement = 100000;
|
||||
|
||||
int[] integers = IntStream.generate(() -> r.nextInt(maxElement)).limit(size).sorted().toArray();
|
||||
Integer[] integers = IntStream.generate(() -> r.nextInt(maxElement)).limit(size).sorted().boxed().toArray(Integer[]::new);
|
||||
|
||||
|
||||
// The element that should be found
|
||||
int shouldBeFound = integers[r.nextInt(size - 1)];
|
||||
|
Reference in New Issue
Block a user