Advertisement
Guest User

TP pivot

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