1、升序排序
对于 int 、 float64 和 string 数组或是分片的排序, go 分别提供了 sort.Ints() 、 sort.Float64s() 和 sort.Strings() 函数, 默认都是从小到大排序。
package mainimport ("fmt""sort")func main() {intList := []int{1,45,2,4,78}float64List := []float64{1.2,4.5,1.1,6.7}stringList := []string{"a","z","x","c"}// int 数组升序排序sort.Ints(intList)fmt.Println(intList)//float 数组升序排序sort.Float64s(float64List)fmt.Println(float64List)//string 数组升序排序sort.Strings(stringList)fmt.Println(stringList)}输出://[1 2 4 45 78]//[1.1 1.2 4.5 6.7]//[a c x z]
