Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package quicksort;
- public class quicksort_methods {
- public static void QuickSort(int[] ARR, int low, int high) {
- if(low < high) {
- int pi = Partition(ARR, low, high);
- QuickSort(ARR, high,pi-1);
- QuickSort(ARR, pi+1, high);
- }
- }
- private static int Partition(int[] ARR, int low, int high) {
- int pivot = ARR[high];
- int i = low-1; // Index for iteration if pivot is bigger
- for(int j = 0; j < high; j++) {
- if(ARR[j] < pivot) {
- i++;
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement