Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. int partition(int t[], int lo, int hi){
  2.     int i = lo+1;
  3.     int j = hi;
  4.     while (1){
  5.         while (less(t[hi], t[lo]) && i < hi){
  6.             i++;
  7.         }
  8.         while (less(t[lo], t[j]) && j > lo){
  9.             j--;
  10.         }
  11.  
  12.         if (i >= j) break;
  13.  
  14.         swap(&t[i], &t[j]);
  15.         i++;
  16.         j--;
  17.     }
  18.     swap(&t[lo], &t[j]);
  19.     return j;
  20. }
  21.  
  22. void quick_sort_aux(int t[], int lo, int hi){
  23.     if (lo >= hi){
  24.         return;
  25.     }
  26.  
  27.     int pivot = partition(t, lo, hi);
  28.     quick_sort_aux(t, lo, pivot-1);
  29.     quick_sort_aux(t, pivot+1, hi);
  30. }
  31.  
  32. void quick_sort(int t[], int size){
  33.    
  34.     quick_sort_aux(t,0, size-1);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement