diff options
| author | Paul Buetow <paul@buetow.org> | 2020-07-15 08:28:21 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2020-07-15 08:28:21 +0100 |
| commit | e6e3b27756974ad7255345c98260918a96f3a476 (patch) | |
| tree | d56e404ca6724a64116aa10cb147161f8e7fcff2 /sort/shell.go | |
| parent | 73ca4d0b86036a41b452212702e6aa669888d740 (diff) | |
fix shell sort
Diffstat (limited to 'sort/shell.go')
| -rw-r--r-- | sort/shell.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sort/shell.go b/sort/shell.go index 99aaf3d..39414f5 100644 --- a/sort/shell.go +++ b/sort/shell.go @@ -17,11 +17,12 @@ func Shell(a []ds.Comparer) []ds.Comparer { for h >= 1 { for i := h; i < length; i++ { for j := i; j >= h; j -= h { - if a[j].LowerThan(a[j-h]) { - tmp := a[j] - a[j] = a[j-h] - a[j-h] = tmp + if a[j-h].Lower(a[j]) { + break } + tmp := a[j] + a[j] = a[j-h] + a[j-h] = tmp } } |
