diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-04-16 20:30:04 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-04-16 20:30:04 +0900 |
| commit | c8ff868327e19cd156573a723214d66119a71b41 (patch) | |
| tree | 2b959f5d9e2ec4b9f520b0259307a781102ffea7 /comparison/OCaml/msort800000.ml | |
| parent | 353b47702094b20d207acf97e1638d2befb4da11 (diff) | |
| parent | 5139486fd68973703b8a68b118eff2ef78def144 (diff) | |
| download | inpla-c8ff868327e19cd156573a723214d66119a71b41.tar.gz inpla-c8ff868327e19cd156573a723214d66119a71b41.zip | |
Merge branch 'develop'
Diffstat (limited to 'comparison/OCaml/msort800000.ml')
| -rw-r--r-- | comparison/OCaml/msort800000.ml | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/comparison/OCaml/msort800000.ml b/comparison/OCaml/msort800000.ml new file mode 100644 index 0000000..1835b98 --- /dev/null +++ b/comparison/OCaml/msort800000.ml @@ -0,0 +1,43 @@ +let rec split (alist : int list) = + match alist with + [] -> ([], []) + | [a] -> ([a], []) + | a::b::cs -> + let (m,n) = split cs in + (a::m, b::m) ;; + +let rec merge (alist : int list) (blist : int list) = + match alist with + [] -> blist + | x::xs -> + match blist with + [] -> x::xs + | y::ys -> + if x<y then x::(merge xs (y::ys)) + else y::(merge (x::xs) ys) ;; + + +let rec msort (alist : int list) = + match alist with + [] -> [] + | a::[] -> [a] + | a::b::[] -> if a<b then [a;b] else [b;a] + | xs -> + let (m,n) = split xs + in merge (msort m) (msort n) ;; + + + +let rec mkRandList n = + match n with + 0 -> [] + | n -> (Random.int 10000)::(mkRandList (n-1)) ;; + +let main = msort (mkRandList 800000) ;; + + +(* +The following error arises: + +Stack overflow during evaluation (looping recursion?). +*) |
