随意记一下sort包的用法。
Sort内置的函数
# func Ints(a []int) 传入一个int的slice
a := []int{2, 1, 6, 4, 3}
sort.Ints(a)
# func IntsAreSorted(a []int) bool 判断slice是否是有序的
# func SearchInts(a []int, x int) int
#SearchInts在递增顺序的a中搜索x,返回x的索引。如果查找不到,返回值是x应该插入a的位置(以保证a的递增顺序),返回值可以是len(a)
# func Float64s(a []float64)
Float64s函数将a排序为递增顺序。
# func Float64sAreSorted(a []float64) bool
Float64sAreSorted检查a是否已排序为递增顺序。
# func SearchFloat64s(a []float64, x float64) int
SearchFloat64s在递增顺序的a中搜索x,返回x的索引。如果查找不到,返回值是x应该插入a的位置(以保证a的递增顺序),返回值可以是len(a)
# func Strings(a []string)
Strings函数将a排序为递增顺序。
# func StringsAreSorted(a []string) bool
StringsAreSorted检查a是否已排序为递增顺序。
# func SearchStrings(a []string, x string) int
SearchStrings在递增顺序的a中搜索x,返回x的索引。如果查找不到,返回值是x应该插入a的位置(以保证a的递增顺序),返回值可以是len(a)。
# func Reverse(data Interface) Interface
# 传入任意数据类型,反转data