冒泡排序
class ArrayUtil {
public static void sort(int data[]){
for(int x = 0; x < data.length;x++){
for(int y = 0; y < data.length - x - 1;y++){// 注意这里的 -x -1 含义;
if(data[y] < data[y + 1]){
int tmp = data[y];
data[y] = data[y + 1];
data[y + 1] = tmp;
}
}
}
}
}
public class HelloWorld {
public static void main(String[] args){
int data [] = new int [] {8,9,0,1,2,3,5,10,7};
ArrayUtil arrayUtil = new ArrayUtil();
arrayUtil.sort(data);
printArray(data);
}
public static void printArray(int temp []){
for(int x = 0;x < temp.length;x++){
System.out.println(temp[x] + ",");
}
}
}
标签:ArrayUtil,int,void,6.6,static,数组,排序,data,public
From: https://www.cnblogs.com/pansidong/p/17455022.html