diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 16:04:50 +0100 |
|---|---|---|
| committer | Paul Buetow <pbuetow@mimecast.com> | 2020-08-08 16:04:50 +0100 |
| commit | d5a41348086fd357f8f74ec55cf38d6236bf5366 (patch) | |
| tree | 149e24c1010c0486aede8940298578dbf832d2ca | |
| parent | 719321d413bcc61e56786399799a9c80e94ab5d8 (diff) | |
fix bug
| -rw-r--r-- | sort/quick.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/sort/quick.go b/sort/quick.go index 72db370..7222515 100644 --- a/sort/quick.go +++ b/sort/quick.go @@ -24,6 +24,7 @@ func quick(a ds.ArrayList) { func quickPartition(a ds.ArrayList) int { i := 0 // Left scan index j := len(a) // Right scan index + hi := j - 1 Insertion(a[0:3]) a.Swap(0, 1) @@ -31,9 +32,15 @@ func quickPartition(a ds.ArrayList) int { for { for i++; a[i] < v; i++ { + if i == hi { + break + } } for j--; v < a[j]; j-- { + if j == 0 { + break + } } // Check scan complete |
