diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 14:32:37 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 14:32:37 +0100 |
| commit | c870dae11a5ec088800a35665d6ac1baa3abef3a (patch) | |
| tree | 901714ce898921077efd0e4f903175a390b6cebf /sort/insertion.go | |
| parent | 0db964a3b8ba57b3677d9d201870ee5ab15b6a30 (diff) | |
refactor quicksort
Diffstat (limited to 'sort/insertion.go')
| -rw-r--r-- | sort/insertion.go | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/sort/insertion.go b/sort/insertion.go index 6663bca..203d4f2 100644 --- a/sort/insertion.go +++ b/sort/insertion.go @@ -5,12 +5,7 @@ import ( ) func Insertion(a ds.ArrayList) ds.ArrayList { - insertion(a, 0, len(a)-1) - return a -} - -func insertion(a ds.ArrayList, lo, hi int) { - for i := lo; i <= hi; i++ { + for i, _ := range a { for j := i; j > 0; j-- { if a[j] > a[j-1] { break @@ -18,4 +13,6 @@ func insertion(a ds.ArrayList, lo, hi int) { a.Swap(j, j-1) } } + + return a } |
