From 8c7809d024e85d0a8acfb794a4db41b0e4bc13e6 Mon Sep 17 00:00:00 2001 From: Shinya Sato Date: Mon, 2 May 2022 09:49:01 +0900 Subject: v0.8.2-1 --- comparison/SML/qsort-260000.sml | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 comparison/SML/qsort-260000.sml (limited to 'comparison/SML/qsort-260000.sml') diff --git a/comparison/SML/qsort-260000.sml b/comparison/SML/qsort-260000.sml new file mode 100644 index 0000000..40bf8b7 --- /dev/null +++ b/comparison/SML/qsort-260000.sml @@ -0,0 +1,41 @@ +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; + + +(* Creates a random list *) +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; + + +(* Validation checks *) +fun validation [] = true + | validation (x::xs) = + let fun validation_cons x [] = true + | validation_cons x (y::ys) = + if x<=y then validation_cons y ys + else false + in + validation_cons x xs + end; + + +(* Main *) +validation(quicksort(mkRandList 260000)); -- cgit v1.2.3