数组的冒泡排序方法

口诀:n个数字来排列两两比较小靠前,外层循环n-1内层循环n-i-1

public static int[] bubbleSort(int[] arr){
    for(int i=0;i){
        for(int j=0;j){
            if(arr[j]>arr[j+1]){
                int temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
    return arr;

 

转载于:https://www.cnblogs.com/yuchenjing/p/8994850.html

你可能感兴趣的:(数组的冒泡排序方法)