简单排序---插入排序

2022-12-24 12:03:33 浏览数 (1)

代码语言:javascript复制
function insertionSort(arr) {
    var temp, inner;
    for (var outer = 1; outer <= arr.length - 1;   outer) {
        temp = arr[outer];
        inner = outer;
        while (inner > 0 && arr[inner - 1] >= temp) {
            arr[inner] = arr[inner - 1];
            --inner;
        }
        arr[inner] = temp
    }
    return arr
}

0 人点赞