Golang实现选择排序


本文摘自网络,作者,侵删。

package main

import "fmt"

func main() {
    var arr []int
    arr = []int{3, 4, 9, 6, 7, 1, 2}
    res := cSort(arr)
    fmt.Println(res)
}

func cSort(arr []int) []int {
    var tmp, tmpIndex int
    count := len(arr)

    for i := 0; i < count-1; i++ {
        tmpIndex = i
        for j := i+1; j < count; j++ {
            if arr[j] < arr[tmpIndex] {
                tmpIndex = j
            }
        }
        tmp = arr[tmpIndex]
        arr[tmpIndex] = arr[i]
        arr[i] = tmp
    }
    
    return arr
}


本文来自:简书

感谢作者:看活一分钟

查看原文:Golang实现选择排序

相关阅读 >>

Golang 什么时候用锁

Go语言学习9-结构体类型

Golang语言社区--unity3d学习 第1期 如何学习unity3d

Golang 1.11 module 做项目版本管理

聊聊Go-ddd-sample

Go实战--使用Golang开发windows gui桌面程序(lxn/walk)

Golang viper 使用记录: 读取不到配置文件json

Golang map是否有顺序

12 Golang defer panic recover

详解Go 中方法与函数的区别

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...