diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-04-15 11:27:58 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-04-15 11:27:58 +0800 |
commit | 8379919686d791e3e003bfb0fad80a990f2710b6 (patch) | |
tree | dac680851fecf381630560b6cb9b8fdbc2fd3a8b | |
parent | a39aea354b071612c071d98125e879fe14c76a54 (diff) | |
download | h99-master.tar.gz h99-master.tar.bz2 h99-master.zip |
-rw-r--r-- | H63.hs | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -1,8 +1,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 +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)) |