summaryrefslogtreecommitdiff
path: root/miralib/ex/quicksort.m
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-04 12:32:20 -0500
committerJakob Kaivo <jkk@ung.org>2022-03-04 12:32:20 -0500
commit55f277e77428d7423ae906a8e1f1324d35b07a7d (patch)
tree5c1c04703dff89c46b349025d2d3ec88ea9b3819 /miralib/ex/quicksort.m
import Miranda 2.066 from upstream
Diffstat (limited to 'miralib/ex/quicksort.m')
-rw-r--r--miralib/ex/quicksort.m12
1 files changed, 12 insertions, 0 deletions
diff --git a/miralib/ex/quicksort.m b/miralib/ex/quicksort.m
new file mode 100644
index 0000000..2da7d55
--- /dev/null
+++ b/miralib/ex/quicksort.m
@@ -0,0 +1,12 @@
+||this is a functional version of quicksort, to see it work, say:
+|| qsort testdata
+||the reason we have to call the function `qsort' rather than `sort' is
+||because there is a `sort' already defined in the standard environment
+
+qsort [] = []
+qsort (a:x) = qsort [b|b<-x;b<=a] ++ [a] ++ qsort[b|b<-x;b>a]
+
+testdata = f 10
+f n = concat(transpose [[0,2..2*n],[2*n-1,2*n-3..1]])
+
+||note that the sort included in the standard environment is merge-sort