Skip to content

Commit bd00022

Browse files
Updated TreeWayQuickSort comments
1 parent b7e7b47 commit bd00022

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/main/java/io/github/marioluan/algorithms/sorting/ThreeWayQuickSort.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,13 @@ private static void sort(Comparable[] a, int lo, int hi) {
6161
// moving keys
6262
while (i <= gt) {
6363
int cmp = a[i].compareTo(v);
64-
if (cmp < 0) {
65-
// makes sure all items to the right are greater than it
64+
if (cmp < 0)
6665
swap(a, lt++, i++);
67-
} else if (cmp > 0) {
68-
// makes sure all items to the right are greater than it
66+
else if (cmp > 0)
6967
swap(a, i, gt--);
70-
} else {
71-
// this happens when we found duplicate key
72-
i++;
73-
}
68+
else
69+
i++; // this happens when we found duplicate keys. E.g.: first round a[i] == v.
70+
7471
}
7572

7673
sort(a, lo, lt - 1);

0 commit comments

Comments
 (0)