aboutsummaryrefslogtreecommitdiff
path: root/comparison/OCaml/qsort800000.ml
blob: 627abd2d16ac74b481ac8232bfab7f213f31e6ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
let rec split pivot (alist : int list) =
  match alist with
    [] -> ([], [])
  | (x::xs) ->
    let (below, above) = split pivot xs in
    if x<pivot then (x::below, above)
    else (below, x::above) ;;

let rec qsort (alist : int list) =
  match alist with
    [] -> []
  | pivot::rest ->
    let (below, above) = split pivot rest
    in (qsort below) @ [pivot] @ (qsort above) ;;




let rec mkRandList n =
  match n with
    0 -> []
  | n -> (Random.int 10000)::(mkRandList (n-1)) ;;

let main = qsort (mkRandList 800000) ;;

(* 
The following error arises:

Stack overflow during evaluation (looping recursion?).
*)