代码如下:
public class test8 {
public static void main(String[] args) {
int[] arr1 = {8, 2, 3, 7, 9};
int w;
int l = 1, ll = 1, pos = 1;
boolean ok;
int k = arr1.length - 1;
System.out.println(arr1.length);
for (int i = 0; i < k; i++) {
ok = true;
for (int j = 0; j < arr1.length - 1; j++) {
if (arr1[j] > arr1[j + 1]) {
w = arr1[j];
arr1[j] = arr1[j + 1];
arr1[j + 1] = w;
ok = false;
pos = j;
}
System.out.println("第" + ll + "小轮:");
ll++;
System.out.println(Arrays.toString(arr1));
System.out.println("-----------");
}
k = pos;
System.out.println("第" + l + "大轮:");
l++;
System.out.println(Arrays.toString(arr1));
System.out.println("================");
if (ok == true) {
return;
}
/*
无优化:16小轮,4大轮;
优化1.0:8小轮,2大轮;
优化2.0:8小轮,2大轮。
助力链接:https://blog.csdn.net/yanxiaolx/article/details/51622286
*/
}
}
}