数据结构--冒泡排序

来源:互联网 发布:扫街软件 编辑:程序博客网 时间:2024/06/16 05:25
冒泡排序(BubbleSort)的基本概念是:依次比较相邻的两个数,将小数放在前面,大数放在后面
public static void test(long[] arr) {
    long temp;    for (int i = 0; i < arr.length - 1; i++) {        for (int j = arr.length -1; j > i; j--) {            if (arr[j] < arr[j - 1]) {                temp = arr[j];                arr[j] = arr[j - 1];                arr[j - 1] = temp;            }        }    }}