summaryrefslogtreecommitdiff
path: root/sort/quick.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2023-04-02 20:22:13 +0300
committerPaul Buetow <paul@buetow.org>2023-04-02 20:22:13 +0300
commit0c6d4ed2e499e3e17165e43803d0d1c6dd0956d9 (patch)
tree6d6a5df53d1dd3e655d24f0423f24bc52ad9784c /sort/quick.go
parentf78ba2cdc6840dbc52a27a2f9fac28f3b61e8b7b (diff)
initial generics
Diffstat (limited to 'sort/quick.go')
-rw-r--r--sort/quick.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/sort/quick.go b/sort/quick.go
index 46b750a..32c1a4d 100644
--- a/sort/quick.go
+++ b/sort/quick.go
@@ -6,12 +6,12 @@ import (
"codeberg.org/snonux/algorithms/ds"
)
-func Quick(a ds.ArrayList) ds.ArrayList {
+func Quick[V ds.Number](a ds.ArrayList[V]) ds.ArrayList[V] {
quick(a)
return a
}
-func quick(a ds.ArrayList) {
+func quick[V ds.Number](a ds.ArrayList[V]) {
if len(a) <= 10 {
Insertion(a)
return
@@ -22,7 +22,7 @@ func quick(a ds.ArrayList) {
quick(a[j+1:])
}
-func quickPartition(a ds.ArrayList) int {
+func quickPartition[V ds.Number](a ds.ArrayList[V]) int {
l := len(a)
i := 0 // Left scan index
j := l // Right scan index
@@ -53,7 +53,7 @@ func quickPartition(a ds.ArrayList) int {
return j
}
-func median(a ds.ArrayList, l int) int {
+func median[V ds.Number](a ds.ArrayList[V], l int) int {
u := rand.Intn(l)
v := rand.Intn(l)
w := rand.Intn(l)