讨论数量:
go 1.19中slices包还没有包含到标准库中(此时slices包还在扩展库中),需要下载扩展库并导入使用
go get golang.org/x/exp
代码中使用
import (
"fmt"
"golang.org/x/exp/slices"
)
func main() {
nums := []int{5, 3, 8, 6, 2, 7, 4, 1}
slices.Sort(nums)
fmt.Println("Sorted slice:", nums)
}
推荐文章: