diff --git a/Exercise_23/Exercise_23_04/Exercise_23_04.class b/Exercise_23/Exercise_23_04/Exercise_23_04.class index 9c811b22..917bbe06 100644 Binary files a/Exercise_23/Exercise_23_04/Exercise_23_04.class and b/Exercise_23/Exercise_23_04/Exercise_23_04.class differ diff --git a/Exercise_23/Exercise_23_04/Exercise_23_04.java b/Exercise_23/Exercise_23_04/Exercise_23_04.java index 2553d9f3..af9f7373 100644 --- a/Exercise_23/Exercise_23_04/Exercise_23_04.java +++ b/Exercise_23/Exercise_23_04/Exercise_23_04.java @@ -20,9 +20,15 @@ public static void quickSort(int[] list, int first, int last) { public static int partition(int[] list, int first, int last) { int middle = list[(list.length - 1) / 2]; // choose the median element as the pivot - int pivot = median(first, middle, last); + // here should parse the element in the list instead of + // index; + int pivot = median(list[first], middle, list[last]); int low = first + 1; // Index for forward search - int high = last; // Index for backward search + // here should not forward the index + // the pivot is choose from median() + // instead of the first element in + // the list + int high = last; // Index for backward search while (high > low) { // Search forward from left @@ -69,4 +75,4 @@ public static int median(int first, int middle, int last) { return Math.max(Math.min(first, middle), Math.min(Math.max(first, middle), last)); } -} \ No newline at end of file +}