400 028 6601

建站动态

根据您的个性需求进行定制 先人一步 抢占小程序红利时代

直接插入排序(go实现)

package main

import "fmt"

func main() {
    arr := []int{11, 2, 7, 11, 88, 91, 23, 14, 12, 33}
    straightInsertSort(arr)
    for i :=0 ; i < len(arr); i++ {
        fmt.Println(arr[i])
    }
}

func straightInsertSort(unsorted []int) {
    for i := 1; i < len(unsorted); i++ {
        if unsorted[i-1] > unsorted[i] {
            temp := unsorted[i]
            var j int
            for j = i - 1; j >= 0 && unsorted[j] > temp; j-- {
                unsorted[j+1] = unsorted[j]
            }
            unsorted[j+1] = temp
        }
    }
}

名称栏目:直接插入排序(go实现)
分享地址:http://www.bluegullmedia.com/article/pdiiej.html

其他资讯

让你的专属顾问为你服务

0.2609s