algorithms/sorting/selection.go
2021-12-16 17:46:10 +02:00

14 lines
274 B
Go

package sorting
func Selection[T any](items []T, less func(a, b T) bool) {
len := len(items)
for i := 0; i < len; i++ {
min := i
for j := i + 1; j < len; j++ {
if less(items[j], items[min]) {
min = j
}
}
items[min], items[i] = items[i], items[min]
}
}