冒泡排序
import java.util.Arrays;
public class MaoPaoPaiXu {
public static void main(String[] args) {
int[] a = {1,2,3,5,7,9,22,44,63,75};
int[] sort = sort(a);
System.out.println(Arrays.toString(sort));
}
public static int[] sort(int[] array){
int temp = 0;
for (int i = 0; i < array.length; i++) {
boolean flag = false;//通过flag标识符减少没有意义的比较
for (int j = 0; j < array.length-1-i; j++) {
if (array[j+1] > array[j]){
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
flag = true;
}
}
if(flag == false){
break;
}
}
return array;
}
}
标签:sort,Java,int,冒泡排序,----,flag,array,public
From: https://www.cnblogs.com/s1mple-han/p/17263894.html