sort.SearchInts(a []int, b int) 从数组a中查找b,前提是a必须有序
sort.SearchFloats(a []float64, b float64) 从数组a中查找b,前提是a必须有序
sort.SearchStrings(a []string, b string) 从数组a中查找b,前提是a必须有序
example
package main; import ( "fmt" "sort" ) func testString () { var arr =[...]float64{13.4,6.8,1.2,0.6,0.5,12.6}; sort.Float64s(arr[:]) fmt.Println(arr[:]) index:=sort.SearchFloat64s(arr[:],12.6) fmt.Println(index) } func main() { testString(); }
输出:
[0.5 0.6 1.2 6.8 12.6 13.4] 4