美文网首页
JAVA冒泡排序(BUBBLE-SORT)

JAVA冒泡排序(BUBBLE-SORT)

作者: 龙儿筝 | 来源:发表于2017-03-31 10:29 被阅读12次
public static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j] > array[j + 1]) {
                    array[j] ^= array[j + 1];
                    array[j + 1] ^= array[j];
                    array[j] ^= array[j + 1];
                }
            }
        }
    }

相关文章

网友评论

      本文标题:JAVA冒泡排序(BUBBLE-SORT)

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