Fork me on GitHub

golang数据结构之选择排序

//SelectSort 选择排序
func SelectSort(arr *[7]int) {
    for i := 0; i < len(arr); i++ {
        tmp := arr[i]
        index := i
        for j := i + 1; j < len(arr); j++ {
            if (*arr)[j] < tmp {
                tmp = (*arr)[j]
                index = j
            }
        }
        if index != i {
            (*arr)[index], (*arr)[i] = (*arr)[i], (*arr)[index]
        }
        fmt.Printf("第%d次选择后的结果是:%v", i, *arr)
    }
}

 

 

posted @ 2019-12-10 16:19  西西嘛呦  阅读(241)  评论(0编辑  收藏  举报