listfct.hs 507 B

12345678910111213141516171819202122232425
  1. -- Slide 32
  2. -- Reverse list order
  3. myexchanger xs zs = case xs of
  4. [] -> zs
  5. y:ys -> myexchanger ys (y:zs)
  6. myreverse xs = myexchanger xs []
  7. -- Delete the first item
  8. mydelete l y = case l of
  9. [] -> []
  10. x:xs -> if x == y then xs else x:(mydelete xs y)
  11. -- Find the maximum
  12. mymaximum l = mymaximumof l 0
  13. mymaximumof l x = case l of
  14. [] -> x
  15. y:ys -> if y > x then mymaximumof ys y else mymaximumof ys x
  16. -- Sort the list
  17. trimax l = if l == []
  18. then []
  19. else let y = mymaximum l in y:(trimax (mydelete l y))