MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Selection

Function Selection

sort/selectionsort.go:5–17  ·  view source on GitHub ↗
(arr []T)

Source from the content-addressed store, hash-verified

3import "github.com/TheAlgorithms/Go/constraints"
4
5func Selection[T constraints.Ordered](arr []T) []T {
6 for i := 0; i < len(arr); i++ {
7 min := i
8 for j := i + 1; j < len(arr); j++ {
9 if arr[j] < arr[min] {
10 min = j
11 }
12 }
13
14 arr[i], arr[min] = arr[min], arr[i]
15 }
16 return arr
17}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected