update quick sort

This commit is contained in:
cinita 2019-01-10 00:43:52 +08:00
parent b9749985c0
commit fc8635016c

View File

@ -24,10 +24,13 @@ public class QuickSort {
int i = p; int i = p;
for(int j = p; j < r; ++j) { for(int j = p; j < r; ++j) {
if (a[j] < pivot) { if (a[j] < pivot) {
int tmp = a[i]; if (i == j) {
a[i] = a[j]; ++i;
a[j] = tmp; } else {
++i; int tmp = a[i];
a[i++] = a[j];
a[j] = tmp;
}
} }
} }