关于冒泡排序的理解
package array;
import java.util.Arrays;
public class Short {
public static void main(String[] args) {
int[] z = {1,4,113,5,213,7,3,4,78,24,23,5,32,1,136,4,3,2};
ShortM(z);
System.out.print(Arrays.toString(z));
}
//冒泡排序
public static int[] ShortM(int[] arrays){
int temp = 0;
for (int i = 0;i<arrays.length-1;i++){
boolean flag = false;
for (int j = 0 ;j< arrays.length-1-i;j++){
if(arrays[j]>arrays[j+1]){//每次比较结束,都会将数组arrays中从0到length-1-i下标的最 //大值放到最后
temp = arrays[j];
arrays[j] = arrays[j+1];
arrays[j+1] = temp;
flag = true;
}
}
if (!flag){//如果第一次比较没有任何排序,则flag为false,即数组原本就为从小到大排列
break;
}
}
return arrays;
}
}
标签:temp,arrays,冒泡排序,int,flag,public
From: https://www.cnblogs.com/qt0312/p/16746521.html