package quicksort; public class quickSort { private int array[]; private int length; public void sort(int[] inputArr) { this.array = inputArr; length = inputArr.length; quickSort(0, length - 1); } private void quickSort(int lowerIndex, int higherIndex) { int i = lowerIndex; int j = higherIndex; int pivot = array[lowerIndex+(higherIndex-lowerIndex)/2]; while (i <= j) { while (array[i] < pivot) { i++; } while (array[j] > pivot) { j--; } if (i <= j) { exchangeNumbers(i, j); i++; j--; } } if (lowerIndex < j) quickSort(lowerIndex, j); if (i < higherIndex) quickSort(i, higherIndex); } private void exchangeNumbers(int i, int j) { int temp = array[i]; array[i] = array[j]; array[j] = temp; } public static void main(String a[]) { quickSort sorter = new quickSort(); int[] input = {5,8,10,1,4,2,7,15,11,9}; sorter.sort(input); for(int i:input){ System.out.print(i); System.out.print(" "); } } }