Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package QuickSort_183_02;
- public class QuickSort_Method {
- public static void QuickSort(int[] arr, int low, int high) {
- if(low < high){
- int PivotIndex = Partition(arr,low,high);
- QuickSort(arr,low,PivotIndex - 1 ); //Recursively call for left part
- QuickSort(arr,PivotIndex + 1, high);//Recursively call for left part
- }
- }
- private static int Partition(int[] arr, int low, int high) {
- int i = (low - 1 ); // Index of current element which we have to swap
- int pivot = arr[high];
- for (int j = low; j < high ; j++) {
- if(arr [j] < pivot){
- i++;
- int TEMP = 0;
- // Spaw if the current element is smaller than pivot
- TEMP = arr[i];
- arr[i] = arr [j];
- arr[j] = TEMP;
- }
- }
- int TEMP;
- TEMP = arr[i+1];
- arr[i+1] = arr[high];
- arr[high] = TEMP;
- return i + 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment