all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,29 @@
|
|||
void quick_sort (int *a, int n) {
|
||||
if (n < 2)
|
||||
return;
|
||||
int p = a[n / 2];
|
||||
int *l = a;
|
||||
int *r = a + n - 1;
|
||||
while (l <= r) {
|
||||
if (*l < p) {
|
||||
l++;
|
||||
continue;
|
||||
}
|
||||
if (*r > p) {
|
||||
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(l, a + n - l);
|
||||
}
|
||||
|
||||
int main () {
|
||||
int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
|
||||
int n = sizeof a / sizeof a[0];
|
||||
quick_sort(a, n);
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue