标签:java array 冒泡 bsp sys ring system 选择 排序
冒泡排序:
System.out.println(Arrays.toString(arr));
int temp = -1;
for(int i=0;i<arr.length;i++) {
for(int j=i+1;j<arr.length;j++) {
if(arr[i]>arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.println(Arrays.toString(arr));
直接选择排序
System.out.println(Arrays.toString(arr));
for(int i=0;i<arr.length;i++) {
int tem = i;
for(int j=i;j<arr.length;j++) {
if(arr[j] < arr[tem]) {
tem = j;
}
}
int temp1 = arr[i];
arr[i] = arr[tem];
arr[tem] = temp1;
}
System.out.println(Arrays.toString(arr));
反转排序
System.out.println(Arrays.toString(arr));
for(int i=0;i<arr.length / 2;i++) {
int temp = arr[i];
arr[i] = arr[arr.length-i-1];
arr[arr.length-i-1] = temp;
}
System.out.println(Arrays.toString(arr));
标签:java array 冒泡 bsp sys ring system 选择 排序
原文地址:http://www.cnblogs.com/xfxy/p/7029443.html