Motivation: Sortieren/Vergleichen)

Einfügen (in monotone Liste)

insert :: Int -> [Int] -> [Int]
insert x ys = case ys of
  [] -> [x] ; y : ys' -> if x < y then .. else ..
Sortieren durch Einfügen:
sort :: [Int] -> [Int]
sort xs = foldr insert [] xs
Einfügen/Sortieren für beliebige Typen:
mit Vergleichsfunktion als zusätzlichem Argument
insert :: (a->a-> Bool) -> a -> [a] -> [a]
insert lt x ys = ... if lt x y then ...



Johannes Waldmann 2013-06-11