forked from inpla/inpla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqsort260000.ml
More file actions
38 lines (28 loc) · 807 Bytes
/
Copy pathqsort260000.ml
File metadata and controls
38 lines (28 loc) · 807 Bytes
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
31
32
33
34
35
36
37
38
open Format
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 rec validation alist =
let rec validation_cons x blist =
match blist with
[] -> true
| y::ys -> if x<=y then (validation_cons y ys) else false
in
match alist with
[] -> true
| x::xs -> validation_cons x xs;;
let () = print_bool (validation (qsort (mkRandList 260000)));;