Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<math.h>
- #pragma warning(disable:4996)
- #define LEN 10
- //sortowanie szybkie 2 podejście
- void qsort(int tab[LEN], int left, int right)
- {
- int pivot = (left + right) / 2; //srodkowy index
- int i = left, j = right, mem;
- while (1)
- {
- while (tab[i] < tab[pivot])
- ++i;
- while (tab[j] > tab[pivot])
- --j;
- if (i >= j) break;
- mem = tab[i];
- tab[i] = tab[j];
- tab[j] = mem;
- }
- if(left - pivot > 2)qsort(tab, left, pivot);
- if (pivot - right > 2)qsort(tab, pivot+1, right);
- return;
- }
- int main()
- {
- int tab[LEN] = { 4, 23, 10, 13, 3, 26, 4, 24, 24, 14 }; // sypie sie na 4
- int left = 0, right = LEN -1;
- qsort(tab, left, right);
- for (int i = 0; i < LEN; ++i)
- printf("%d, ", tab[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement