package com.hailong.array;
import java.util.Arrays;
/**
* date:2023/8/8
*/
public class Bubbling {
public static void main(String[] args) {
int[] arr = {5, 2, 1, 8, 4, 6, 3, 7, 0, 1};
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;
}
}
}
System.out.println(Arrays.toString(arr));
}
}
Java实现冒泡排序
最新推荐文章于 2024-08-28 20:58:28 发布