aboutsummaryrefslogtreecommitdiff
path: root/comparison/SML/isort-40000.sml
blob: 973d6e64bf24a0b3ead7c43eb637a0f508634216 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(* 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;
    
    
(* 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;
    
insertsort (mkRandList 40000);