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

Function Exchange

sort/exchangesort.go:11–21  ·  view source on GitHub ↗
(arr []T)

Source from the content-addressed store, hash-verified

9import "github.com/TheAlgorithms/Go/constraints"
10
11func Exchange[T constraints.Ordered](arr []T) []T {
12 for i := 0; i < len(arr)-1; i++ {
13 for j := i + 1; j < len(arr); j++ {
14 if arr[i] > arr[j] {
15 arr[i], arr[j] = arr[j], arr[i]
16 }
17 }
18 }
19
20 return arr
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected