package hackerrank;

import java.util.Scanner;

/**
 * https://www.hackerrank.com/challenges/quicksort3
 */
public class QuicksortInPlace {
    private static void quicksort(int[] array) {
        // TODO
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = in.nextInt();
        }
        quicksort(array);
    }
}

@@ -194,15 +194,1150 @@
     
-// TODO
+quicksort(array, 0, array.length - 1);%0A    %7D%0A%0A    private static void quicksort(int%5B%5D array, int begin, int end) %7B%0A        if (begin %3E end) %7B%0A            return;%0A        %7D%0A        int p = partition(array, begin, end);%0A        quicksort(array, begin, p - 1);%0A        quicksort(array, p + 1, end);%0A    %7D%0A%0A    private static int partition(int%5B%5D array, int begin, int end) %7B%0A        int pivot = begin;%0A        int left = pivot + 1;%0A        int right = end;%0A        while (true) %7B%0A            while (left %3C= end && array%5Bleft%5D %3C array%5Bpivot%5D) %7B%0A                left++;%0A            %7D%0A            if (left %3E end) %7B%0A                break;%0A            %7D%0A            while (right %3E= begin && array%5Bpivot%5D %3C array%5Bright%5D) %7B%0A                right--;%0A            %7D%0A            if (right %3C begin) %7B%0A                break;%0A            %7D%0A            if (left %3E= right) %7B%0A                break;%0A            %7D%0A            swap(array, left, right);%0A        %7D%0A        swap(array, pivot, right);%0A        return right;%0A    %7D%0A%0A    private static void swap(int%5B%5D array, int i, int j) %7B%0A        int tmp = array%5Bi%5D;%0A        array%5Bi%5D = array%5Bj%5D;%0A        array%5Bj%5D = tmp;
 %0A   

Update Quicksort: In-Place