2020-06-27【冒泡排序】

2020-06-27  本文已影响0人  skillplus
image.png
image.png
package com.example;

/**
 * 冒泡排序
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {13, 25, 65, 2, 6};

        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        System.out.println(arr);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读