让我们一起爱米兰
站内搜搜:
移动设备
请扫描二维码
或访问
m.milan100.com
您所在的位置 -> 米兰百分百 -> golang -> Golang切片降序排列

Golang切片降序排列

点击数:925 发表时间:2020-12-04 10:49:56 作者: 来源链接:
分享到:
分享到微信
package main

import (
    "sort"
    "fmt"
)

type intSlice []int
func (p intSlice) Len() int           { return len(p) }
func (p intSlice) Less(i, j int) bool { return p[i] < p[j] }
func (p intSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

func main() {
    dd := make(intSlice,0)
    dd = append(dd,1,3,2,5)
    sort.Sort(sort.Reverse(dd))
    fmt.Println(dd)
}


5
很 好
5
一 般
5
差 劲
热门新闻
相关文章
上一篇: 编写自己的Golang库并托管到gitee
下一篇: cannot find package "golang.org/x/sys/unix"解决方案
评论区
匿名

返回首页 | 收藏本页 | 回到顶部
Copyright 2010. 米兰百分百 Powered By Bridge.
京ICP备15050557号