--- a/progs/lecture3.scala Sat Aug 29 16:05:59 2020 +0100
+++ b/progs/lecture3.scala Tue Oct 13 10:21:21 2020 +0100
@@ -34,6 +34,23 @@
l.map(test).flatten
+// naive quicksort with "On" function
+
+def sortOn(f: Int => Int, xs: List[Int]) : List[Int] = {
+ if (xs.size < 2) xs
+ else {
+ val pivot = xs.head
+ val (left, right) = xs.partition(f(_) < f(pivot))
+ sortOn(f, left) ::: pivot :: sortOn(f, right.tail)
+ }
+}
+
+sortOn(identity, List(99,99,99,98,10,-3,2))
+sortOn(n => - n, List(99,99,99,98,10,-3,2))
+
+
+
+
// Recursion Again ;o)
//====================