Guest User

Untitled

a guest
Jul 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. long quick_sort(item_t * A, const int & n)
  2. {
  3.   // base case
  4.   if (1 == n) return 0;
  5.   long counter = 0;
  6.   // choose pivot
  7.   set_pivot_at_beginning(A, n);
  8.   // partition around pivot: assumes pivot is at the beginning
  9.   const int pivot_idx = partition(A, n);
  10.   const int lsize = pivot_idx;
  11.   const int rsize = n - pivot_idx - 1;
  12.   counter += lsize + rsize;
  13.   // sort left and right around pivot
  14.   if(lsize > 0) {
  15.     counter += quick_sort(A, lsize) ;
  16.   }
  17.   if(rsize > 0) {
  18.     counter += quick_sort(A + pivot_idx + 1, rsize) ;
  19.   }
  20.   return counter;
  21. }
Add Comment
Please, Sign In to add comment