public static void main(String[] args) {
int[] arr = {5, 9, 7, 6, 4, 3, 1, 8, 2};
System.out.println(Arrays.toString(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 m = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = m;
}
}
}
System.out.println(Arrays.toString(arr));
}
回顾一下冒泡排序
最新推荐文章于 2024-08-12 19:27:52 发布