minibear2333 / blog-comment

0 stars 0 forks source link

切片排序sort包的使用 | Go语言精进之路 #24

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

切片排序sort包的使用 | Go语言精进之路

golang的sort包提供了部分切片排序的函数和用户自定义数据集的函数。 排序切片 # func Example1() { arry := []int{5,8,3,1,4,2,7,6} fmt.Println(arry) sort.Ints(arry) fmt.Println(arry) // Output: // [5 8 3 1 4 2 7 6] // [1 2 3 4 5 6 7 8] } 排序用户自定义数据集 # type Person struct { Name string Age int } func (p Person) String() string { return fmt.Sprintf("%s: %d", p.Name, p.Age) } // ByAge implements sort.Interface for []Person based on // the Age field.

https://golang.coding3min.com/%E7%95%AA%E5%A4%96.%E5%B8%B8%E7%94%A8%E6%93%8D%E4%BD%9C/%E5%88%87%E7%89%87%E6%8E%92%E5%BA%8Fsort%E5%8C%85%E7%9A%84%E4%BD%BF%E7%94%A8/

GhostFanta commented 3 years ago

小哥你有个typo, pepole 应该是people :)

minibear2333 commented 3 years ago

感谢贡献!