Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int partition(int t[], int lo, int hi){
- int i = lo+1;
- int j = hi;
- while (1){
- while (less(t[hi], t[lo]) && i < hi){
- i++;
- }
- while (less(t[lo], t[j]) && j > lo){
- j--;
- }
- if (i >= j) break;
- swap(&t[i], &t[j]);
- i++;
- j--;
- }
- swap(&t[lo], &t[j]);
- return j;
- }
- void quick_sort_aux(int t[], int lo, int hi){
- if (lo >= hi){
- return;
- }
- int pivot = partition(t, lo, hi);
- quick_sort_aux(t, lo, pivot-1);
- quick_sort_aux(t, pivot+1, hi);
- }
- void quick_sort(int t[], int size){
- quick_sort_aux(t,0, size-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement