From 554a7a259f3feefb586374ac5a3b57acc99a4446 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Jul 2020 08:53:17 +0100 Subject: add insertion sort --- sort/selection.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'sort/selection.go') 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 } -- cgit v1.2.3