Standard library / sort

sort.Reverse()

Wraps a sort.Interface with its Less ordering reversed; does not itself rearrange elements. Expected stdout: '[3 2 1]\n'.

Formal Syntax & Structure

go syntaxgo
func Reverse(data Interface) Interface

Parameters & Attributes

NameTypeDescription
dataInterfaceCollection implementing sort.Interface.

Return Value

Interface

Wraps a sort.Interface with its Less ordering reversed; does not itself rearrange elements.

Working Example

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