Standard library / sort

sort.Sort()

Sorts the supplied collection in place using Len, Less and Swap. Equal elements need not retain original order. Expected stdout: '[1 2 3]\n'.

Formal Syntax & Structure

go syntaxgo
func Sort(data Interface)

Parameters & Attributes

NameTypeDescription
dataInterfaceCollection implementing sort.Interface.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := sort.IntSlice{3, 1, 2}  sort.Sort(a)  fmt.Println(a)}
Go Reference