Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void quickSortByX(Point[] arr, int begin, int end) {
- if (begin < end) {
- int partitionIndex = partition(arr, begin, end);
- quickSortByX(arr, begin, partitionIndex - 1);
- quickSortByX(arr, partitionIndex + 1, end);
- }
- }
- private int partition(Point[] arr, int begin, int end) {
- Point pivot = arr[end];
- int i = (begin-1);
- for (int j = begin; j < end; j++) {
- if (arr[j].x <= pivot.x) {
- i++;
- Point swapTemp = arr[i];
- arr[i] = arr[j];
- arr[j] = swapTemp;
- }
- }
- Point swapTemp = arr[i+1];
- arr[i+1] = arr[end];
- arr[end] = swapTemp;
- return i+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement