java 冒泡选择排序

字数 0阅读 15

public final class ArrayUtil {
    
    private ArrayUtil(){};
    
    public static final void arrayMax(){
        
        int[] arr = {1,43,43,4,23};
        int max = arr[0];
        for(int i = 0;i<arr.length;i++){
            if (max > arr[i]) {
                
                max = max ^ arr[i];
                arr[i] = max ^ arr[i];
                max = max ^ arr[i];
            }
        }
        
        System.out.println(max + "");
    }
    
    public static final int[] selectSort(){
        int[] arr = {23,4324,43244,22,3};
        int tmp = 0;
        for(int i=0;i<arr.length - 1;i++) {
            for(int j=i+1;j<arr.length;j++) {
                if (arr[i] > arr[j]) {
                    tmp = arr[i];
                    arr[i] = arr[j];
                    arr[j] = tmp;
                }
            }
        }
        return arr;
    }
    public static final int[] selectReduceSort(){
        int[] arr = {23,4324,43244,22,3};
        int tmp = 0;
        int index = 0;
        for(int i=0;i<arr.length - 1;i++){
            index = i;
            for(int j=i+1;j<arr.length;j++){
                if(arr[index] > arr[j]) {
                    index = j;
                }
            }
            if (index != i) {
                tmp = arr[index];
                arr[index] = arr[i];
                arr[i] = tmp;
            }
        }
        return arr;
    }
    
    public static final int[] maoPaoSort(){
        int[] arr = {234,432432,432,44};
        int tmp = 0;
        for(int i=0;i<arr.length-1;i++) {
            for(int j=0;j<arr.length-1-i;j++) {
                if (arr[j] > arr[j+1]) {
                    tmp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = tmp;
                }
            }
        }
        return arr;
    }
}

推荐阅读更多精彩内容