commit c181935613004958c9998c39b973a3eb84847ad0
parent 18a2e8353784f0cf97e75d4eed7026f664675ce4
Author: thing1 <thing1@seacrossedlovers.xyz>
Date: Tue, 21 Apr 2026 10:05:58 +0100
lecture notes
Diffstat:
3 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/CS10120/20.04.26.md b/CS10120/20.04.26.md
@@ -0,0 +1,3 @@
+# 20/04/26
+
+
diff --git a/CS10720/20.04.26.md b/CS10720/20.04.26.md
@@ -0,0 +1 @@
+# 20/04/26
diff --git a/CS10720/code/sort.go b/CS10720/code/sort.go
@@ -0,0 +1,46 @@
+package main
+
+import (
+ "fmt"
+ "math/rand"
+)
+
+func makeSides[T any](arr []T, cmp func(T, T) int) ([]T, []T, T) {
+ var lhs, rhs []T
+ index := rand.Int() % len(arr)
+ pivot := arr[index]
+ for i, el := range arr {
+ if i == index {
+ continue
+ }
+
+ if cmp(pivot, el) <= 0 {
+ lhs = append(lhs, el)
+ } else {
+ rhs = append(rhs, el)
+ }
+ }
+ return lhs, rhs, pivot
+}
+
+func sort[T any](arr []T, cmp func(T, T) int) []T {
+ lhs, rhs, pivot := makeSides(arr, cmp)
+ if len(lhs) > 1 {
+ lhs = sort(lhs, cmp)
+ }
+ if len(rhs) > 1 {
+ rhs = sort(rhs, cmp)
+ }
+
+ out := append([]T{}, lhs...)
+ out = append(out, pivot)
+ out = append(out, rhs...)
+ return out
+}
+
+func main() {
+ fmt.Println(sort([]int{4, 5, 6, 2, 6, 2, 8, 9},
+ func(a, b int) int {
+ return b - a
+ }))
+}