Standard library / sort

sort.Float64Slice.Swap()

Exchanges elements at two valid indices in the receiver; invalid indices panic. Expected stdout: '[2.5 1.5 3.5]\n'.

Formal Syntax & Structure

go syntaxgo
func (x Float64Slice) Swap(i, j int)

Parameters & Attributes

NameTypeDescription
iintIndex or start position.
jintSecond index or exclusive end position.

Working Example

Example Snippetgo
package main
import (  "fmt"  "sort")
func main() {  a := sort.Float64Slice([]float64{1.5, 2.5, 3.5})  a.Swap(0, 1)  fmt.Println(a)}
Go Reference