public static void bubbleSort(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
// 学生类定义 class Student {
String name;
int score;
public Student(String name, int score) {
this.name = name;
this.score = score;
}
}
// 按分数降序排序 Student[] students = new Student[50]; // ... 初始化学生数据 Arrays.sort(students, (s1, s2) -> s2.score - s1.score);
// 性能测试示例 int[] largeArray = generateRandomArray(1000000);
long startTime = System.currentTimeMillis(); Arrays.sort(largeArray); long endTime = System.currentTimeMillis();
System.out.println("Arrays.sort()耗时: " + (endTime - startTime) + "ms");