Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void quicksort(int[] array, int left_begin, int right_begin) {
- if(left_begin < 0 || right_begin >= array.length){ return; }
- int pivot = array[right_begin]; //nebo array[(left_begin + right_begin) / 2];
- int left_index, right_index, pom;
- left_index = left_begin;
- right_index = right_begin;
- Do { //najdeme hodnoty vhodne k prohozeni
- while (array[left_index] <= pivot && left_index < right_begin) {
- left_index++; }
- while (array[right_index] >= pivot && right_index > left_begin) {
- right_index--;}
- if (left_index <= right_index) { //prohodime je a posuneme indexy
- pom = array[left_index];
- array[left_index] = array[right_index];
- array[right_index] = pom;
- if (left_index < right_begin){ left_index++; }
- if (right_index > left_begin){ right_index--; }
- }
- } while (left_index < right_index);
- //rekurzivni volani k setrideni casti pole s mensimi a vetsimi hodnotami
- if (right_index > left_begin){ quicksort(array, left_begin, right_index); }
- if (left_index < right_begin){ quicksort(array, left_index, right_begin); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement