summaryrefslogtreecommitdiff
path: root/sort/quick3way.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-08-08 16:55:09 +0100
committerPaul Buetow <pbuetow@mimecast.com>2020-08-08 16:55:09 +0100
commit4a4d109bab43930299c72db1fa19b3be394791d8 (patch)
treef3a0fd5f96cc0669aa9a44a507b7cbafb9013594 /sort/quick3way.go
parent9bee249738c6bbea23a3618bd487d8d046dd2fc4 (diff)
better quicksort
Diffstat (limited to 'sort/quick3way.go')
-rw-r--r--sort/quick3way.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/sort/quick3way.go b/sort/quick3way.go
index 5263432..8434111 100644
--- a/sort/quick3way.go
+++ b/sort/quick3way.go
@@ -18,13 +18,12 @@ func quick3Way(a ds.ArrayList) {
return
}
- lt := 0 // Lower than
- i := 1 // lt..i contain duplicates
+ lt := 0 // Lower than
+ i := 1 // lt..i contain duplicates
gt := l - 1 // Greater than
- Insertion(a[0:3])
- a.Swap(0, 1)
- v := a[0] // Partitioning item
+ a.Swap(0, median(a, l))
+ v := a[0]
for i <= gt {
switch {