Format code with prettier (#3375)

This commit is contained in:
acbin
2022-10-03 17:23:00 +08:00
committed by GitHub
parent 32b9b11ed5
commit e96f567bfc
464 changed files with 11483 additions and 6189 deletions

View File

@@ -32,7 +32,12 @@ class InterpolationSearch {
while (start <= end && key >= array[start] && key <= array[end]) {
// Probing the position with keeping
// uniform distribution in mind.
int pos = start + (((end - start) / (array[end] - array[start])) * (key - array[start]));
int pos =
start +
(
((end - start) / (array[end] - array[start])) *
(key - array[start])
);
// Condition of target found
if (array[pos] == key) {
@@ -55,7 +60,11 @@ class InterpolationSearch {
Random r = new Random();
int size = 100;
int maxElement = 100000;
int[] integers = IntStream.generate(() -> r.nextInt(maxElement)).limit(size).sorted().toArray();
int[] integers = IntStream
.generate(() -> r.nextInt(maxElement))
.limit(size)
.sorted()
.toArray();
// the element that should be found
Integer shouldBeFound = integers[r.nextInt(size - 1)];
@@ -64,13 +73,22 @@ class 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",
shouldBeFound, integers[atIndex], atIndex, size));
String.format(
"Should be found: %d. Found %d at index %d. An array length %d",
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));
format(
"Found by system method at an index: %d. Is equal: %b",
toCheck,
toCheck == atIndex
)
);
}
}