diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2021-10-24 23:04:45 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2021-10-24 23:04:45 +0900 |
| commit | 787dc13c837f0955fbd85b8f26a05d720d361333 (patch) | |
| tree | fec3abebb1e867e8b2239d7cf07b4c7d13ce0f81 /comparison/SML/msort-800000.sml | |
| parent | e607a57dfafb784c4e27da143214afb2ccd07fbf (diff) | |
| download | inpla-787dc13c837f0955fbd85b8f26a05d720d361333.tar.gz inpla-787dc13c837f0955fbd85b8f26a05d720d361333.zip | |
Upload the comparison directory
Diffstat (limited to 'comparison/SML/msort-800000.sml')
| -rw-r--r-- | comparison/SML/msort-800000.sml | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/comparison/SML/msort-800000.sml b/comparison/SML/msort-800000.sml new file mode 100644 index 0000000..2a33649 --- /dev/null +++ b/comparison/SML/msort-800000.sml @@ -0,0 +1,45 @@ +(* https://stackoverflow.com/questions/25839939/understanding-merge-sort-in-ml *) + +fun split [] = ([], []) + | split [a] = ([a], []) + | split (a::b::cs) = + let + val (m,n) = split cs + in + (a::m, b::n) + end; + +fun merge ([], ys) = ys + | merge (xs, []) = xs + | merge (x::xs, y::ys) = + if x<y then + x::merge(xs, y::ys) + else + y::merge(x::xs, ys); + +fun msort [] = [] + | msort [a] = [a] + | msort [a,b] = if a<b then [a,b] else [b,a] + | msort xs = + let + val (m,n) = split xs; + in + merge (msort m, msort n) + 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; + + +msort (mkRandList 800000); + + |
