冒泡排序
import java.util.Arrays;
public class bubbleSort {
public static void main(String[] args) {
int[] a = {2,1,5,6,3,2,9,19,11};
bubbleSort(a);
System.out.println(Arrays.toString(a));
}
public static void bubbleSort(int[ ] a){
// 从前往后冒泡 升序
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] > a[j+1]){
flag = true;
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
if (flag == false){
break;
}
}
}
}
}
标签:temp,int,冒泡排序,bubbleSort,flag,public
From: https://www.cnblogs.com/GXEndeavor/p/18675254