Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. void quicksort(int[] array, int left_begin, int right_begin) {
  2. if(left_begin < 0 || right_begin >= array.length){ return; }
  3. int pivot = array[right_begin]; //nebo array[(left_begin + right_begin) / 2];
  4. int left_index, right_index, pom;
  5. left_index = left_begin;
  6. right_index = right_begin;
  7. Do { //najdeme hodnoty vhodne k prohozeni
  8. while (array[left_index] <= pivot && left_index < right_begin) {
  9. left_index++; }
  10. while (array[right_index] >= pivot && right_index > left_begin) {
  11. right_index--;}
  12.  
  13. if (left_index <= right_index) { //prohodime je a posuneme indexy
  14. pom = array[left_index];
  15. array[left_index] = array[right_index];
  16. array[right_index] = pom;
  17. if (left_index < right_begin){ left_index++; }
  18. if (right_index > left_begin){ right_index--; }
  19. }
  20. } while (left_index < right_index);
  21.  
  22. //rekurzivni volani k setrideni casti pole s mensimi a vetsimi hodnotami
  23. if (right_index > left_begin){ quicksort(array, left_begin, right_index); }
  24. if (left_index < right_begin){ quicksort(array, left_index, right_begin); }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement