还有一种选择排序:
package com.heima.yaphets;
public class Array {
public static void main(String[] args) {
int[] arr={2,8,23,12,34,0};
method(arr);
for(int i:arr){
System.out.print(i+" ");
}
}
public static void method(int[] arr) {
for (int i = 0; i < arr.length-1; i++) {
for (int j = i+1; j < arr.length; j++) {
if(arr[i]>arr[j]){
int t=arr[i];
arr[i]=arr[j];
arr[j]=t;
}
}
}
}
} |