summaryrefslogtreecommitdiff
path: root/H57.hs
blob: 0af879fd4ddeb3adabd704c0aa429b8251204061 (plain)
1
2
3
4
5
6
7
8
9
10
11
import Tree

construct :: Ord a => [a] -> Tree a
construct = foldl add Empty

add :: Ord a => Tree a -> a -> Tree a
add Empty x = Branch x Empty Empty
add t@(Branch a t1 t2) x = case compare x a of 
    LT -> Branch a (add t1 x) t2
    GT -> Branch a t1 (add t2 x)
    EQ -> t