// quick sort class QuickSort { public static void main (String[] args) { int[] list = {8,6,5,4,2,3,7}; printl (list); System.out.println(); quickSort (list, 0, list.length - 1); printl (list); System.out.println(); } static int[] quickSort (int[] list, int low, int high) { System.out.print("quickSort("); printl (list); System.out.println("," + low + "," + high + ")"); if (low < high) { int mid = partition (list, low, high); quickSort (list, low, mid - 1); quickSort (list, mid + 1, high); } return list; } static int partition (int[] list, int start, int end) { int pivot = list[start]; do { // look for a number smaller than the pivot starting // from the end of the list while (start < end && list[end] >= pivot) end--; if (start < end) { // a smaller number found list[start] = list[end]; // now find a number larger than the pivot // from the start while (start < end && list[start] <= pivot) start++; if (start < end) { // a larger number found list[end] = list[start]; } } } while (start < end); // done -- move the pivot back to the array list[start] = pivot; return start; } public static void printl (int[] list) { System.out.print ("["); for (int i = 0; i < list.length-1; i++) System.out.print (list[i] + ","); System.out.print (list[list.length-1] + "]"); } }