package com.lovcoding.day06;

import java.util.Arrays;

public class TestArr04_Sort_3 {
    //选择排序
    public static void main(String[] args) {
        int[] arr = {11,31,53,16,18,1,1231,123,123,432,5,32,5,435,4326,456,45,1,123,213,213,12,4,21,4,21,4,214,21,4,21,4,21};

        int lun = 0;
        int count = 0;
        for (int i = 1; i < arr.length; i++) {
            lun++;
            //标识
            boolean flag = true;
            for (int j = 0; j < arr.length-i; j++) {
                count++;
                //第一个和第二个比较
                if (arr[j] > arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    //改变状态
                    flag = false;
                }
            }
            //没有改
            if (flag){
                break;
            }
        }

        System.out.println(lun);
        System.out.println(count);
        System.out.println(Arrays.toString(arr));
    }
}
