Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "quick_sort.h"
- 2
- 3 inline int *choose_pivot(int *left, int *right)
- 4 {
- 5 // FIX ME
- 6 if (*left < *right)
- 7 return left;
- 8 else
- 9 return right;
- 10 }
- 11
- 12 int *partition(int *left, int *right, int *pivot)
- 13 {
- 14 // FIX ME
- 15 while (right != left)
- 16 {
- 17 if (*pivot > *right)
- 18 {
- 19 int *aux;
- 20 aux = right;
- 21 right = pivot;
- 22 pivot = aux;
- 23 }
- else
- 25 right--;
- 26 if(*pivot < *left)
- 27 {
- 28 int *aux;
- 29 aux = left;
- 30 left = pivot;
- 31 pivot = aux;
- 32 }
- 33 else
- 34 left++;
- 35 }
- 36 return pivot;
- 37 }
- 38
- 39 void quick_sort(int *left, int *right)
- 40 {
- 41 // FIX ME
- 42 if (left == right)
- 43 return;
- 44 int *pivot = left;
- 45 pivot = partition(left,right,pivot);
- 46 quick_sort(pivot +1, right);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement