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

@ -2,10 +2,10 @@ package com.thealgorithms.searches;
import static java.lang.String.format;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
import java.util.Arrays;
import java.util.Random;
import java.util.stream.Stream;
import com.thealgorithms.devutils.searches.SearchAlgorithm;
/**
* Binary search is one of the most popular algorithms This class represents
@ -60,8 +60,11 @@ public final class IterativeBinarySearch implements SearchAlgorithm {
Random r = new Random();
int size = 100;
int maxElement = 100000;
Integer[] integers
= Stream.generate(() -> r.nextInt(maxElement)).limit(size).sorted().toArray(Integer[]::new);
Integer[] integers = Stream
.generate(() -> r.nextInt(maxElement))
.limit(size)
.sorted()
.toArray(Integer[]::new);
// the element that should be found
Integer shouldBeFound = integers[r.nextInt(size - 1)];
@ -70,13 +73,22 @@ public final class IterativeBinarySearch implements SearchAlgorithm {
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
)
);
}
}