美文网首页
2020-06-27【冒泡排序】

2020-06-27【冒泡排序】

作者: skillplus | 来源:发表于2020-06-27 21:45 被阅读0次
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);
    }
}

相关文章

网友评论

      本文标题:2020-06-27【冒泡排序】

      本文链接:https://www.haomeiwen.com/subject/rftbfktx.html