Standard library / sort
sort.Interface
Contract for indexed sorting: Len returns count, Less defines a strict weak ordering and Swap exchanges items. Methods must agree on the same collection. Expected stdout: '[1 2 3]\n'.
Formal Syntax & Structure
go syntaxgo
type Interface interface { Len() int Less(i, j int) bool Swap(i, j int)}Working Example
Example Snippetgo
package main
import ( "fmt" "sort")
func main() { var a sort.Interface = sort.IntSlice{3, 1, 2} sort.Sort(a) fmt.Println(a)}