diff options
Diffstat (limited to 'sort')
| -rw-r--r-- | sort/insertion.go | 2 | ||||
| -rw-r--r-- | sort/selection.go | 2 | ||||
| -rw-r--r-- | sort/shell.go | 9 | ||||
| -rw-r--r-- | sort/sorted.go | 2 |
4 files changed, 8 insertions, 7 deletions
diff --git a/sort/insertion.go b/sort/insertion.go index d14c275..8e4af30 100644 --- a/sort/insertion.go +++ b/sort/insertion.go @@ -9,7 +9,7 @@ func Insertion(a []ds.Comparer) []ds.Comparer { for i := 0; i < length; i++ { for j := i; j > 0; j-- { - if a[j].HigherThan(a[j-1]) { + if a[j].Higher(a[j-1]) { break } tmp := a[j] diff --git a/sort/selection.go b/sort/selection.go index 2782460..d084fc0 100644 --- a/sort/selection.go +++ b/sort/selection.go @@ -9,7 +9,7 @@ func Selection(a []ds.Comparer) []ds.Comparer { for i := 0; i < length; i++ { min := i for j := i + 1; j < length; j++ { - if a[min].HigherThan(a[j]) { + if a[min].Higher(a[j]) { min = j } } 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 } } diff --git a/sort/sorted.go b/sort/sorted.go index a24de19..b29e3c6 100644 --- a/sort/sorted.go +++ b/sort/sorted.go @@ -4,7 +4,7 @@ import "algorithms/ds" func Sorted(a []ds.Comparer) bool { for i := len(a) - 1; i > 0; i-- { - if a[i].LowerThan(a[i-1]) { + if a[i].Lower(a[i-1]) { return false } } |
