冒泡排序
public class Main {
public static void main(String[] args) {
int[] arr = {10, 8, 3, 14, 85, 21, 2, 19, 221, 100};
test(arr);
System.out.print("输出结果:");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
public static void test(int[] arr) {
for (int i = 0; i < arr.length - 1; i++) {
boolean flag = true;
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
flag = false;
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
if (flag) break;
System.out.println("第" + (i + 1) + "排序:");
for (int a = 0; a < arr.length; a++) {
System.out.print(arr[a] + " ");
}
System.out.println();
}
}
}
标签:arr,int,System,++,length,排序,三大,out
From: https://www.cnblogs.com/huxiaoan1/p/16758124.html