blob: a4cef88c2625a74895bd5117ccc6ea5fdefb78be (
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
36
37
38
39
|
{-
http://www.codecodex.com/wiki/Insertion_sort#Standard_ML
-}
import System.Random
isort [] = []
isort (x:xs) = insert x (isort xs)
insert x [] = [x]
insert x (y:ys) =
if x<=y then x:y:ys
else y:(insert x ys)
{-
main = print $ isort [3,2,8,5]
-}
randomList :: Int -> IO([Int])
randomList 0 = return []
randomList n = do
r <- randomRIO (1,10000)
rs <- randomList (n-1)
return (r:rs)
validation [] = True
validation (x:xs) = validation_cons x xs
validation_cons x [] = True
validation_cons x (y:ys) =
if x<=y then validation_cons y ys
else False
main = do
list <- randomList 20000
let sorted = isort list
print (validation sorted)
|