12345678910111213141516171819202122232425 |
- -- Slide 32
- -- Reverse list order
- myexchanger xs zs = case xs of
- [] -> zs
- y:ys -> myexchanger ys (y:zs)
- myreverse xs = myexchanger xs []
- -- Delete the first item
- mydelete l y = case l of
- [] -> []
- x:xs -> if x == y then xs else x:(mydelete xs y)
- -- Find the maximum
- mymaximum l = mymaximumof l 0
- mymaximumof l x = case l of
- [] -> x
- y:ys -> if y > x then mymaximumof ys y else mymaximumof ys x
- -- Sort the list
- trimax l = if l == []
- then []
- else let y = mymaximum l in y:(trimax (mydelete l y))
|