aboutsummaryrefslogtreecommitdiff
path: root/comparison/SML/qsort-800000.sml
diff options
context:
space:
mode:
Diffstat (limited to 'comparison/SML/qsort-800000.sml')
-rw-r--r--comparison/SML/qsort-800000.sml27
1 files changed, 27 insertions, 0 deletions
diff --git a/comparison/SML/qsort-800000.sml b/comparison/SML/qsort-800000.sml
new file mode 100644
index 0000000..e27af56
--- /dev/null
+++ b/comparison/SML/qsort-800000.sml
@@ -0,0 +1,27 @@
+fun quicksort nil = nil
+ | quicksort (pivot :: rest) =
+ let
+ fun split(nil) = (nil,nil)
+ | split(x :: xs) =
+ let
+ val (below, above) = split(xs)
+ in
+ if x < pivot then (x :: below, above)
+ else (below, x :: above)
+ end;
+ val (below, above) = split(rest)
+ in
+ quicksort below @ [pivot] @ quicksort above
+ end;
+
+
+(* mkRandList *)
+local
+ val nextInt = Random.randRange(1,10000);
+ val r = Random.rand(1,1);
+in
+ fun mkRandList 0 = []
+ | mkRandList n = (nextInt r)::(mkRandList (n-1))
+end;
+
+quicksort (mkRandList 800000);