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 : ....