package _04_常见算法;

public class Test4 {

    public static void main(String[] args) {
        // 那外层循环元素和内存循环元素进行比较
        // 定义一个数组
        int[] arr = {1,5,3,2,4};
        // 0 1 2 3
        for (int i = 0; i < arr.length-1; i++) {
            // i = 0  j = 1234
            // i = 1  j= 2 3 4
            // i = 2  j= 3 4
            // i = 3  j =4
            for (int j = 1 + i; j < arr.length; j++) {
                // 拿外层和内存循环比较
                if(arr[j] < arr[i] ){
                    int temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
        // 遍历数组
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] +" ");
        }

    }
}
