Sort

https://golang.org/pkg/sort/

基本用法

sort.Slice
sort.SliceStable // 將相同值的元素保持原順序
sort.Ints
sort.Float64s
sort.Strings

基本 sort

slice sort

實作 slice sort 方法

自行實作 slice 的 sort ,實作時必須要實作三個 func (Len, Less, Swap) 缺一不可。

實作後即可使用 sort.Sort 會依照實作時的 Less 方法排序。

Last updated

Was this helpful?