Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long quick_sort(item_t * A, const int & n)
- {
- // base case
- if (1 == n) return 0;
- long counter = 0;
- // choose pivot
- set_pivot_at_beginning(A, n);
- // partition around pivot: assumes pivot is at the beginning
- const int pivot_idx = partition(A, n);
- const int lsize = pivot_idx;
- const int rsize = n - pivot_idx - 1;
- counter += lsize + rsize;
- // sort left and right around pivot
- if(lsize > 0) {
- counter += quick_sort(A, lsize) ;
- }
- if(rsize > 0) {
- counter += quick_sort(A + pivot_idx + 1, rsize) ;
- }
- return counter;
- }
Add Comment
Please, Sign In to add comment