java insertion sorting


for (int i = 1; i < arr.length; i++){
            for (int j = i; j > 0; j--){
                if (arr[j] < arr[j-1]){//arr[j]向前挪位
                    int temp = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = temp; 
                }else{ // 如果比最大的还大,则不比较
                    break;
                }

            }
        }

猜你喜欢

转载自blog.csdn.net/qq_28197211/article/details/80755749
今日推荐