Skip to content
Go

sort API Reference

Go sort package — sorting slices and custom collections.

By EZ4Code Team

sort

Package sort provides primitives for sorting slices and user-defined collections.

sort.Sort(data sort.Interface)

Sort data in place. data must implement sort.Interface (Len, Less, Swap).

Returns: void

sort.Slice(x any, less func(i, j int) bool)

Sort x in place using a less function. Convenience wrapper avoiding sort.Interface.

Returns: void

sort.Strings(a []string)

Sort a slice of strings in increasing order in place.

Returns: void

sort.Ints(a []int)

Sort a slice of ints in increasing order in place.

Returns: void

sort.Float64s(a []float64)

Sort a slice of float64s in increasing order in place.

Returns: void

sort.Search(n int, f func(int) bool) int

Binary search. Uses f to find the smallest index i in [0,n) at which f(i) is true.

Returns: int

More Go API References