golang排序,是我们锻炼逻辑必不可少的,不会可以QQ联系 2817228206。相互学习。本人是小白。写的比较简单,推荐用官网的包。
package main
import "fmt"
func numsum(arr []int) []int {
sum := []int{}
ksum := 0
vsum := 0
for _, v := range arr {
for ka, va := range arr {
if va > v || len(arr) == 1 {
ksum = ka
vsum = va
}
}
}
sum = append(sum, ksum, vsum)
return sum
}
func main() {
var arr = []int{}
arr = append(arr, 1, 4, 5, 6, 7, 5)
var arrlen = 6
tr := []int{}
for n := 0; n < arrlen; n++ {
e := numsum(arr)
t := e[0]
tr = append(tr, e[1])
arr = append(arr[:t], arr[t+1:]...)
}
fmt.Println(tr)
}
![](https://static.studygolang.com/200318/28cf7c595f51e61db36fc12463fa5efe.png)
有疑问加站长微信联系(非本文作者)
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)