Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- public class QuickSortMethods {
- public static void QuickSort(int[] ARR, int low, int high) {
- if (low < high) {
- int pi = partition(ARR, low, high);
- QuickSort(ARR, low, pi - 1);
- QuickSort(ARR, pi + 1, high);
- }
- }
- public static 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) {
- //swap
- i++;
- int temp = ARR[j];
- ARR[j] = ARR[i];
- ARR[i] = 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