//最初版
public static void maopao1(int[] arr){
int k = 1;
for (int i=0; i<=arr.length; i++){
for (int j=i+1; j<= arr.length-1; j++){
int num;
k++;
if (arr[i] > arr[j]){
num = arr[i];
arr[i] = arr[j];
arr[j] = num;
}
}
}
System.out.println("(初版)排序后数组:"+ Arrays.toString(arr));
System.out.println("(初版)共计:"+k+"步");
}
//升级版
public static void maopao2(int[] arr){
int k = 1;
boolean b = true;
for (int i=0; i<=arr.length; i++){
if (b){
b = false;
for (int j=i+1; j<= arr.length-1; j++){
int num;
k++;
if (arr[i] > arr[j]){
num = arr[i];
arr[i] = arr[j];
arr[j] = num;
b = true;
}
}
}
}
System.out.println("(升级版)排序后数组:"+ Arrays.toString(arr));
System.out.println("(升级版)共计:"+k+"步");
}