Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Quick_Sort_181;
- 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){
- i++;
- //swap
- int temp = arr[j];
- arr[j] = arr[i];
- arr[i] = temp;
- }
- }
- //put the pivot element at right position
- int temp = arr[high];
- arr[high] = arr[i+1];
- arr[i+1] = temp;
- return i + 1;
- }
- public static void main(String[] args) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement