冒泡排序
作者:互联网
public static void main(String[] args) {
int[] a = {4, 1, 5, 6, 7, 3, 230};
int temp = 0;
// 判断走多少次
for (int i = 0; i < a.length-1; i++) {
boolean flag = false;
for (int j = 0; j < a.length - 1 - i; j++) {
if (a[j + 1] < a[j]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
flag = true;
}
}
if (flag == false) {
break;
}
}
System.out.println(Arrays.toString(a)); [1, 3, 4, 5, 6, 7, 230]
}
标签:false,temp,int,冒泡排序,++,flag,230 来源: https://www.cnblogs.com/yongchunshuo/p/16538013.html