Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
m (→‎{{header|ooRexx}}: correct output tag)
m (→‎{{header|C}}: Remove the comment about the bug in the prior version. Move swap and increment to their own lines.)
Line 651: Line 651:
if (*l < p) {
if (*l < p) {
l++;
l++;
continue;
}
}
if (*r > p) {
else if (*r > p) {
r--;
}
else {
int t = *l;
*l = *r;
*r = t;
l++;
r--;
r--;
continue; // we need to check the condition (l <= r) every time we change the value of l or r
}
}
int t = *l;
*l++ = *r;
*r-- = t;
}
}
quick_sort(a, r - a + 1);
quick_sort(a, r - a + 1);
quick_sort(l, a + n - l);
quick_sort(l, a + n - l);
}
}

int main () {
int main () {
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};