冒泡排序

import java.util.Arrays;

/**
 * 冒泡排序
 * @author 玖洲林
 * Create Date 2019-08-16 下午 04:27
 */
public class h5 {
    public static void main(String[] args) {
        int[] nums = {9,7,58,24,24,28,15,74,51,574,145};
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 - i; j++) {
                if(nums[j] > nums[j + 1]){
                    int temp = nums[j];
                    nums[j] = nums[j+1];;
                    nums[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(nums));
        //输出结果 [7, 9, 15, 24, 24, 28, 51, 58, 74, 145, 574]
    }
}

《冒泡排序》上有1条评论

发表评论