|
Go balíček |
|
![]()
package main
|
|
import (
"fmt"
"slices"
)
|
|
func main() {
|
|
|
Třídicí funkce jsou generické a fungují pro jakýkoli uspořádaný zabudovaný typ. Seznam uspořádaných typů najdete v cmp.Ordered. |
strs := []string{"c", "a", "b"}
slices.Sort(strs)
fmt.Println("Řetězce:", strs)
|
|
Příklad třídění |
ints := []int{7, 2, 4}
slices.Sort(ints)
fmt.Println("Inty: ", ints)
|
|
Balíček |
s := slices.IsSorted(ints)
fmt.Println("Setříděný: ", s)
}
|
$ go run sorting.go
Řetězce: [a b c]
Inty: [2 4 7]
Setříděný: true
|
Další příklad: Třídění s funkcemi.