java学生成绩快速排序
时间: 2023-12-16 15:28:36 浏览: 125
以下是Java语言版本实现快速排序的例子:
```java
public class QuickSort {
public static void quickSort(int[] array, int low, int high) {
if (array == null || array.length == 0) {
return;
}
if (low >= high) {
return;
}
int middle = low + (high - low) / 2;
int pivot = array[middle];
int i = low, j = high;
while (i <= j) {
while (array[i] < pivot) {
i++;
}
while (array[j] > pivot) {
j--;
}
if (i <= j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}
if (low < j) {
quickSort(array, low, j);
}
if (high > i) {
quickSort(array, i, high);
}
}
public static void main(String[] args) {
int[] array = {24, 15, 36, 40, 10, 50, 3, 89, 67};
int low = 0;
int high = array.length - 1;
quickSort(array, low, high);
System.out.println("Sorted array: " + Arrays.toString(array)); // 输出:Sorted array: [3, 10, 15, 24, 36, 40, 50, 67, 89]
}
}
```
阅读全文