go sort排序

package main

import (
    "fmt"
    "sort"
)

func main() {
    str := []string{"", "", "d", "b","c", }
    sort.Strings(str)
    fmt.Println(str)

    ints := []int{5,4,3,2,1}
    sort.Ints(ints)
    fmt.Println(ints)

    floats := []float64{1.1, 0.4, 9.3, 2.1}
    sort.Float64s(floats)
    fmt.Println(floats)

    uints := []uint8{4,2,1,5,5}
    sort.Slice(uints, func(i, j int) bool {
        return uints[i] < uints[j]
    })
    fmt.Println(uints)
}

 

posted @ 2020-03-24 15:52  眼镜儿  阅读(1004)  评论(0编辑  收藏  举报