func Float64s(a []float64) // Float64s 以升序排序 float64 切片
func Float64sAreSorted(a []float64) bool // Float64sAreSorted 判定 float64 切片是否已经进行排序
func Ints(a []int) // Ints 以升序排列 int 切片。
func IntsAreSorted(a []int) bool // IntsAreSorted 判断 int 切片是否已经按升序排列。
func IsSorted(data Interface) bool // IsSorted 判断数据是否已经排序。包括各种可sort的数据类型的判断.
func Strings(a []string) // Strings 以升序排列 string 切片。
func StringsAreSorted(a []string) bool // StringsAreSorted 判断 string 切片是否已经按升序排列。
package main
import (
"fmt"
"sort"
)
func main() {
a := []int{1, 3, 5, 4, 2}
b := []float64{1.1, 2.3, 5.3, 3.4}
c := []string{"ds", "ca", "ab", "sd"}
if !sort.IntsAreSorted(a) {
sort.Ints(a)
}
if !sort.Float64sAreSorted(b) {
sort.Float64s(b)