Skip to content

Latest commit

 

History

History
23 lines (20 loc) · 407 Bytes

插入排序.md

File metadata and controls

23 lines (20 loc) · 407 Bytes

插入排序

原理

待更新


代码如下:

let insetSort = function (arr) {
    let inner, temp;
    for (let outer = 1, len = arr.length; outer < len; outer++) {
        temp = arr[outer]
        inner = outer
        while (inner > 0 && arr[inner - 1] > temp) {
            arr[inner] = arr[inner - 1]
            inner--
        }
        arr[inner] = temp
    }
    return arr
}