Sorting Slices
sort.Slice and helpers.
Why Sorting Matters
Sorting puts elements in a defined order. Go's sort package from the standard library handles this efficiently.
You rarely write your own sort algorithm in Go. Instead you call helpers that work on slices.
Importing sort
To use the package, import it with import "sort". It lives in the standard library, so no external download is needed.
package main
import (
"fmt"
"sort"
)
func main() {
fmt.Println("sort imported")
_ = sort.IntsAreSorted([]int{1, 2, 3})
}All lessons in this course
- Sorting Slices
- Custom Sort Orders
- Searching Sorted Data
- Stable Sorting