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

@ -45,19 +45,21 @@ public final class QuickSelect {
return list.get(index);
}
private static <T extends Comparable<T>> int selectIndex(List<T> list, int n) {
private static <T extends Comparable<T>> int selectIndex(
List<T> list,
int n
) {
return selectIndex(list, 0, list.size() - 1, n);
}
private static <T extends Comparable<T>> int selectIndex(
List<T> list,
int left,
int right,
int n
List<T> list,
int left,
int right,
int n
) {
while (true) {
if (left == right)
return left;
if (left == right) return left;
int pivotIndex = pivot(list, left, right);
pivotIndex = partition(list, left, right, pivotIndex, n);
if (n == pivotIndex) {
@ -71,11 +73,11 @@ public final class QuickSelect {
}
private static <T extends Comparable<T>> int partition(
List<T> list,
int left,
int right,
int pivotIndex,
int n
List<T> list,
int left,
int right,
int pivotIndex,
int n
) {
T pivotValue = list.get(pivotIndex);
Collections.swap(list, pivotIndex, right);
@ -99,15 +101,13 @@ public final class QuickSelect {
Collections.swap(list, right, storeIndexEq);
return (n < storeIndex)
? storeIndex
: Math.min(n, storeIndexEq);
return (n < storeIndex) ? storeIndex : Math.min(n, storeIndexEq);
}
private static <T extends Comparable<T>> int pivot(
List<T> list,
int left,
int right
List<T> list,
int left,
int right
) {
if (right - left < 5) {
return partition5(list, left, right);
@ -129,9 +129,9 @@ public final class QuickSelect {
}
private static <T extends Comparable<T>> int partition5(
List<T> list,
int left,
int right
List<T> list,
int left,
int right
) {
List<T> ts = list.subList(left, right);
ts.sort(Comparator.naturalOrder());