Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static inline
- int* choose_pivot(int *left, int *right) {
- /* FIX ME */
- }
- /*
- * partition(left, right, pivot): push value less than *pivot on the left
- * return the new pivot.
- */
- int* partition(int *left, int *right, int *pivot) {
- /* FIX ME */
- }
- /*
- * quick_sort(left, right)
- */
- void quick_sort(int *left, int *right) {
- /* FIX ME */
- }
- static inline
- int* choose_pivot(int *left, int *right) {
- return &left[(right - left)/2];
- }
- void swap(int *a, int *b)
- {
- int c = *a;
- *a = *b;
- *b = c;
- }
- int* partition(int *left, int *right, int *pivot) {
- int *i, *q;
- q = right;
- i = left ;
- while ( q > pivot )
- {
- while ( pivot < i )
- pivot++;
- while ( q > i )
- q--;
- if ( *q > *pivot )
- {
- swap(pivot,q);
- }
- }
- swap(left, q);
- return q ;
- }
- void quick_sort(int *left, int *right) {
- if(left >= right)
- return;
- int *pivot = partition(left, right, choose_pivot(left, right));
- quick_sort(left, pivot-1);
- quick_sort(pivot + 1, right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement