1 public static int partition(int[] a, int f, int b) { 2 int pivot = a[f]; 3 while (f < b) { 4 while (f < b && a[b] >= pivot) { 5 b--; 6 } 7 while (f < b && a[f] < pivot) { 8 f++; 9 }10 if (f < b) {11 int tmpB = a[b];12 a[b] = a[f];13 a[f] = tmpB;14 }15 } 16 return b;17 }18 19 public static void quickSort(int[] a, int f, int b) {20 if (f < b) {21 int division = partition(a, f, b);22 quickSort(a, f, division);23 quickSort(a, division + 1, b);24 }25 }
1 public static int partition(int[] a, int f, int b) { 2 int pivot = a[f]; 3 while (f < b) { 4 while (f < b && a[b] >= pivot) { 5 b--; 6 } 7 while (f < b && a[f] < pivot) { 8 f++; 9 }10 if (f < b) {11 int tmpB = a[b];12 a[b] = a[f];13 a[f] = tmpB;14 }15 } 16 return b;17 }18 19 public static void quickSort(int[] a, int f, int b) {20 if (f < b) {21 int division = partition(a, f, b);22 quickSort(a, f, division);23 quickSort(a, division + 1, b);24 }25 }