summaryrefslogtreecommitdiff
path: root/sort/quick2.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2020-08-08 13:01:36 +0100
committerPaul Buetow <pbuetow@mimecast.com>2020-08-08 13:01:36 +0100
commit390333bb314f6cb25adc5716ea383112860ed342 (patch)
tree2b87d5741d84b2cd2d7c74eaaa0f522c3a8a221c /sort/quick2.go
parentdeaa4e1c33cd2c1c75f698881918688055abfa51 (diff)
add parallelquick and so on
Diffstat (limited to 'sort/quick2.go')
-rw-r--r--sort/quick2.go43
1 files changed, 0 insertions, 43 deletions
diff --git a/sort/quick2.go b/sort/quick2.go
deleted file mode 100644
index 688e410..0000000
--- a/sort/quick2.go
+++ /dev/null
@@ -1,43 +0,0 @@
-package sort
-
-import (
- "algorithms/ds"
-)
-
-// Quick2 uses a 3-way partitioning so it is more efficient
-// dealing with duplicates
-func Quick2(a ds.ArrayList) ds.ArrayList {
- a = Shuffle(a)
- quick2(a, 0, len(a)-1)
- return a
-}
-
-func quick2(a ds.ArrayList, lo, hi int) {
- if hi <= lo {
- return
- }
-
- lt := lo // Lower than
- i := lo + 1 // lt..i contain duplicates
- gt := hi // Greater than
- v := a[lo] // Partitioning item
-
- for i <= gt {
- switch a[i].Compare(v) {
- case -1:
- a.Swap(lt, i)
- lt++
- i++
- case 1:
- a.Swap(i, gt)
- gt--
- default:
- // Duplicate
- i++
- }
- }
- // Now a[lo..lt-1] < v = a[lt..gt] < a[gt+1..hi]
-
- quick2(a, lo, lt-1)
- quick2(a, gt+1, hi)
-}