题解 | #排序#

排序

https://www.nowcoder.com/practice/2baf799ea0594abd974d37139de27896

using System;
using System.Collections.Generic;


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 将给定数组排序
     * @param arr int整型一维数组 待排序的数组
     * @return int整型一维数组
     */
    public List<int> MySort (List<int> arr) {
        // write code here
        
        int temp=0;
        for(int i=1;i<arr.Count;i++){
            for(int j=0;j<i;j++){
                
                if(arr[i]<arr[j]){
                    temp=arr[i];
                    for(int k=i;k>j;k--){
                        arr[k]=arr[k-1];
                    }
                    arr[j]=temp;

                }

            }



        }
        return arr;

    }




}

全部评论

相关推荐

08-19 17:40
Java
吴offer选手:666 打老板了吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务