blob: 0996960e46cca0a11cec603d6f2e64398ea9f1cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
|
import Tree
import Control.Applicative
completeBinaryTree n = makeTree 1
where makeTree x
| x > n = Empty
| otherwise = Branch 'x' (makeTree (2*x)) (makeTree (2*x+1))
isCompleteBinaryTree t = b>a where
[a, b] = getZipList $ maxmin t 1
maxmin Empty m = ZipList [0, m]
maxmin (Branch _ l r) m = ZipList [max.(max m),min] <*> (maxmin l (2*m)) <*> (maxmin r (2*m + 1))
|