diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-04-05 15:33:17 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-04-05 15:33:17 +0800 |
commit | ef5f19da8865b53f6edf68041a8e270a28031955 (patch) | |
tree | 4c3b214c61665f9b73354416a66225106525efa8 | |
parent | 13c0046a6dbd41b15358e76856922144ac76e768 (diff) | |
download | h99-ef5f19da8865b53f6edf68041a8e270a28031955.tar.gz h99-ef5f19da8865b53f6edf68041a8e270a28031955.tar.bz2 h99-ef5f19da8865b53f6edf68041a8e270a28031955.zip |
+H55 +H56 +Tree
-rw-r--r-- | H55.hs | 6 | ||||
-rw-r--r-- | H56.hs | 8 | ||||
-rw-r--r-- | Tree.hs | 4 |
3 files changed, 18 insertions, 0 deletions
@@ -0,0 +1,6 @@ +import Tree + +cbalTree :: Int -> [Tree Char] +cbalTree 0 = [Empty] +cbalTree n = let (q, r) = (n-1) `quotRem` 2 in + [ Branch 'x' x y | i <- [q .. q + r], x <- cbalTree i, y <- cbalTree $ n - i - 1] @@ -0,0 +1,8 @@ +import Tree + +mirror :: Tree a -> Tree a -> Bool +mirror Empty Empty = True +mirror a@(Branch _ a1 a2) b@(Branch _ b1 b2) = (mirror a1 b2) && (mirror a2 b1) +mirror _ _ = False + +symmetric t = mirror t t @@ -0,0 +1,4 @@ +module Tree where + +data Tree a = Empty | Branch a (Tree a) (Tree a) + deriving (Show, Eq) |