Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://pastebin.com/2mfpRaFT ----> QuickSortMain
- public class QuickSortMethods
- {
- public void quickSort(int[] arr, int low, int high)
- {
- if (low < high)
- {
- int pivot = partition(arr, low, high);
- quickSort(arr, low, pivot-1);
- quickSort(arr, pivot+1, high);
- }
- }
- private int partition(int[] arr, int low, int high)
- {
- int pivot = arr[high];
- int i = low -1;
- for (int j = low; j < high; j++)
- {
- if (arr[j] < pivot)
- {
- i++;
- //swap
- int temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- }
- }
- int temp =arr[high];
- arr[high] = arr[i+1];
- arr[i+1] = temp;
- return i+1;
- }
- }
Add Comment
Please, Sign In to add comment