blob: b902c7ad64432aee3fd3337dd60b6af28bcb5a29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
package sort
import (
"codeberg.org/snonux/algorithms/ds"
)
func Selection[V ds.Number](a ds.ArrayList[V]) ds.ArrayList[V] {
l := len(a)
for i := 0; i < l; i++ {
min := i
for j := i + 1; j < l; j++ {
if a[min] > a[j] {
min = j
}
}
if min == i {
continue
}
a.Swap(i, min)
}
return a
}
|