Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int partition(int arr[], int left, int right) {
- // Pick a pivot point. Can be any element.
- int pivot = arr[(left + right) / 2];
- while (left <= right) {
- while (arr[left] < pivot) {
- left++;
- }
- while (arr[right] > pivot) {
- right--;
- }
- if (left <= right) {
- swap(arr, left, right);
- left++;
- right--;
- }
- }
- return left;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement