题解 | #排序#

排序

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

/**
 * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
 *
 * 将给定数组排序
 * @param arr int整型一维数组 待排序的数组
 * @param arrLen int arr数组长度
 * @return int整型一维数组
 * @return int* returnSize 返回数组行数
 */

int* MySort(int* arr, int arrLen, int* returnSize ) {
    //插入排序
    *returnSize = arrLen;
    for(int i =0;i<arrLen; i++){
        int end = i;
        int temp = arr[end];
        while(end>0){
            if(arr[end -1]>temp){
                arr[end]=arr[end-1];
                end--;
            }
            else break;
        }
        arr[end]=temp;
    }
    return arr;
}

全部评论

相关推荐

李橙子:结果虽不够理想,但过程本身已是宝贵的淬炼。能把学习机会放在薪酬之前,证明你目光长远。先踏实进去,用这段时间扎实学好Python后端,把公司项目吃透,你的价值会在下一份工作中完全体现。这个起点,值得。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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