数组的几种排序
1.冒泡排序
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));
2.直接选择排序
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));
3.反转排序
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)); }