sorting _ golang

Go's sort package implements sorting for builtins and user-defined types. We'll look at sorting for builtins first

package main

import (
    "fmt"
    "sort"
)

func main() {

    strs := []string{"c", "a", "b"}
    sort.Strings(strs)
    fmt.Println("Strings:", strs)

    ints := []int{7, 2, 4}
    sort.Ints(ints)
    fmt.Println("Ints: ", ints)

    s := sort.IntsAreSorted(ints)
    fmt.Println("Sorted: ", s)
}
Strings: [a b c]
Ints:  [2 4 7]
Sorted:  true

总结 :

  1 : ....

posted on 2015-03-20 14:54  xjk112  阅读(173)  评论(0编辑  收藏  举报