Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. void quickSort(vector<int> arr, int left, int right) {
  2. int i = left, j = right;
  3. int tmp;
  4.  
  5.  
  6.  
  7. if (arr[left]>arr[left+1]){ /*1 MÉTODO DE ESCOLHA DO PIVÔ*/
  8. pivot = arr[left];
  9. }
  10. else pivot = arr[left+1];
  11.  
  12.  
  13.  
  14. if (arr[left]>arr[(left + right) / 2]){ /*2 MÉTODO DE ESCOLHA DO PIVÔ*/
  15. pivot = arr[left];
  16. }
  17. else pivot = arr[(left + right) / 2];
  18.  
  19.  
  20.  
  21.  
  22. if (arr[left]>arr[(left + right) / 2]){ /*3 MÉTODO DE ESCOLHA DO PIVÔ*/
  23. pivot = arr[left];
  24. }
  25. else pivot = arr[(left + right) / 2];
  26.  
  27.  
  28.  
  29.  
  30. while (i <= j) {
  31. while (arr[i] < pivot)
  32. i++;
  33. while (arr[j] > pivot)
  34. j--;
  35. if (i <= j) {
  36. tmp = arr[i];
  37. arr[i] = arr[j];
  38. arr[j] = tmp;
  39. i++;
  40. j--;
  41. }
  42. };
  43.  
  44. /* recursion */
  45. if (left < j)
  46. quickSort(arr, left, j);
  47. if (i < right)
  48. quickSort(arr, i, right);
  49.  
  50. cout << endl;
  51. for (int i=0; i<5; i++){
  52. cout << arr[i];
  53. if (i!= (5-1)) cout << "-";
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement