blob: d3648cc061f5cca7ec52a625215df80ce5c58a1a (
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
31
32
33
34
35
|
(* http://www.codecodex.com/wiki/Insertion_sort#Standard_ML *)
fun insertsort [] = []
| insertsort (x::xs) =
let fun insert (x, []) = [x]
| insert (x, y::ys) =
if x<=y then x::y::ys
else y::insert(x, ys)
in insert(x, insertsort xs)
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(insertsort(mkRandList 20000));
|