Go标准库
Go标准库 sort排序
## 排序 - **Sort(data Interface)** :排序data。本函数不能保证排序的稳定性(即不保证相等元素的相对次序不变)。 - **Stable(data Interface)** :排序data,并保证排序的稳定性,相等元素的相对次序不变 - **Reverse(data Interface) Interface** :包装一个Interface接口并返回一个新的Interface接口,对该接口排序可生成递减序列 - **IsSorted(data Interface) bool** :检查data是否已经被排序 - **Search(n int, f func(int) bool) int** :采用二分法搜索找到[0, n)区间内最小的满足f(i)==true的值i。 ## 整数排序 - **Ints(a []int)** :将a排序为递增顺序 - **IntsAreSorted(a []int) bool** :检查a是否已排序为递增顺序 - **SearchInts(a []int, x int) int** :在递增顺序的a中搜索x,返回x的索引。如果查找不到,返回值是x应该插入a的位置(以保证a的递增顺序),返回值可以是len(a)。 - **type IntSlice** 给[]string添加方法以满足Interface接口,以便排序为递增序列 - func (p IntSlice) Len() int - func (p IntSlice) Less(i, j int) bool - func (p IntSlice) Search(x int) int - func (p IntSlice) Sort() - func (p IntSlice) Swap(i, j int) ## 浮点数排序 - **Float64s(a []float64)** :将a排序为递增顺序 - **Float64sAreSorted(a []float64) bool** :检查a是否已排序为递增顺序 - **SearchFloat64s(a []float64, x float64) int** :在递增顺序的a中搜索x,返回x的索引。如果查找不到,返回值是x应该插入a的位置(以保证a的递增顺序),返回值可以是len(a)。 - **type Float64Slice** 给[]string添加方法以满足Interface接口,以便排序为递增序列 - func (p Float64Slice) Len() int - func (p Float64Slice) Less(i, j int) bool - func (p Float64Slice) Search(x float64) int - func (p Float64Slice) Sort() - func (p Float64Slice) Swap(i, j int) ## 字符串排序 - **Strings(a []string)** :将a排序为递增顺序 - **StringsAreSorted(a []string) bool** :d检查a是否已排序为递增顺序 - **SearchStrings(a []string, x string) int** :在递增顺序的a中搜索x,返回x的索引。如果查找不到,返回值是x应该插入a的位置(以保 证a的递增顺序),返回值可以是len(a) - **type StringSlice** 给[]string添加方法以满足Interface接口,以便排序为递增序列 - func (p StringSlice) Len() int - func (p StringSlice) Less(i, j int) bool - func (p StringSlice) Search(x string) int - func (p StringSlice) Sort() - func (p StringSlice) Swap(i, j int)
顶部
收展
底部
[TOC]
目录
Go标准库 fmt格式化操作
Go标准库 time时间接口
Go标准库 strings字符串
Go标准库 strconv字符串转换
Go标准库 sort排序
Go标准库 runtime运行环境
Go标准库 sync同步操作
Go标准库 atomic原子性
Go标准库 path路径
Go标准库 filepath文件路径
Go标准库 http
相关推荐
Gin框架