Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Задание 16. Быстрая сортировка*/
- // переписать!
- #include <stdio.h>
- void qsortx(int *a, size_t low, size_t high) {
- size_t i, j;
- int tmp, pivot;
- i = low;
- j = high;
- pivot = a[(low + (high-low)/2)];
- do {
- while (a[i] < pivot) {
- i++;
- }
- while (a[j] > pivot) {
- j--;
- }
- if (i <= j) {
- if (a[i] > a[j]) {
- tmp = a[i];
- a[i] = a[j];
- a[j] = tmp;
- }
- i++;
- if (j > 0) {
- j--;
- }
- }
- } while (i <= j);
- if (i < high) {
- qsortx(a, i, high);
- }
- if (j > low) {
- qsortx(a, low, j);
- }
- }
- int main(void) {
- int n, a[64];
- scanf("%d\n", &n);
- for(int i = 0; i < n; ++i)
- scanf("%d", &a[i]);
- qsortx(a, 0, n - 1);
- for(int i = 0; i < n; ++i)
- printf("%d ", a[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement