summaryrefslogtreecommitdiff
path: root/sort/selection.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2020-07-14 08:53:17 +0100
committerPaul Buetow <paul@buetow.org>2020-07-14 08:53:17 +0100
commit554a7a259f3feefb586374ac5a3b57acc99a4446 (patch)
tree33ad06e30abb352609dd4f75306504f6548caec8 /sort/selection.go
parent7f0751cad2196932f16f753fdaf53bc3eea670b8 (diff)
add insertion sort
Diffstat (limited to 'sort/selection.go')
-rw-r--r--sort/selection.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/sort/selection.go b/sort/selection.go
index e2a774c..2782460 100644
--- a/sort/selection.go
+++ b/sort/selection.go
@@ -7,18 +7,18 @@ import (
func Selection(a []ds.Comparer) []ds.Comparer {
length := len(a)
for i := 0; i < length; i++ {
- max := i
+ min := i
for j := i + 1; j < length; j++ {
- if a[max].HigherThan(a[j]) {
- max = j
+ if a[min].HigherThan(a[j]) {
+ min = j
}
}
- if max == i {
+ if min == i {
continue
}
tmp := a[i]
- a[i] = a[max]
- a[max] = tmp
+ a[i] = a[min]
+ a[min] = tmp
}
return a
}