Skip to content

Commit def0a41

Browse files
author
Alex Klymenko
committed
refactor: fix readability issues,a and redundant check
1 parent c042a56 commit def0a41

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/main/java/com/thealgorithms/sorts/PatienceSort.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private static <T extends Comparable<T>> List<List<T>> formPiles(final T[] array
4747
for (T x : array) {
4848
int pos = Collections.binarySearch(lastElements, x);
4949
if (pos < 0) {
50-
pos = ~pos; // bitwise complement, which is equivalent to (-pos - 1)
50+
pos = -pos - 1;
5151
}
5252

5353
if (pos < piles.size()) {
@@ -75,9 +75,7 @@ private static <T extends Comparable<T>> List<List<T>> formPiles(final T[] array
7575
private static <T extends Comparable<T>> PriorityQueue<PileNode<T>> mergePiles(final List<List<T>> piles) {
7676
PriorityQueue<PileNode<T>> pq = new PriorityQueue<>();
7777
for (List<T> pile : piles) {
78-
if (!pile.isEmpty()) {
79-
pq.add(new PileNode<>(pile.removeLast(), pile));
80-
}
78+
pq.add(new PileNode<>(pile.removeLast(), pile));
8179
}
8280
return pq;
8381
}

0 commit comments

Comments
 (0)