public static void bubbleSort(int[] array) {
boolean swapped = true;
for (int i = 1; swapped && i <= array.length - 1; i++) {
swapped = false;
for (int j = 0; j < array.length - i; j++) {
if (array[j] > array[j + 1]) {
// 交换两个元素
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
swapped = true;
}
网友评论