diff options
author | Joe Zhao <ztuowen@gmail.com> | 2015-04-05 21:22:20 +0800 |
---|---|---|
committer | Joe Zhao <ztuowen@gmail.com> | 2015-04-05 21:22:20 +0800 |
commit | 897055910d8bda98b3454b6f66ad697edc4676b3 (patch) | |
tree | 3cdb8b63aa195aea8c51497f06a41a50fba9ea3d | |
parent | ef5f19da8865b53f6edf68041a8e270a28031955 (diff) | |
download | h99-897055910d8bda98b3454b6f66ad697edc4676b3.tar.gz h99-897055910d8bda98b3454b6f66ad697edc4676b3.tar.bz2 h99-897055910d8bda98b3454b6f66ad697edc4676b3.zip |
+57 +58
-rw-r--r-- | H55.hs | 1 | ||||
-rw-r--r-- | H56.hs | 1 | ||||
-rw-r--r-- | H57.hs | 11 | ||||
-rw-r--r-- | H58.hs | 12 |
4 files changed, 25 insertions, 0 deletions
@@ -1,3 +1,4 @@ +module H55 where import Tree cbalTree :: Int -> [Tree Char] @@ -1,3 +1,4 @@ +module H56 where import Tree mirror :: Tree a -> Tree a -> Bool @@ -0,0 +1,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 @@ -0,0 +1,12 @@ +import Tree +import H55 +import H56 + +symCbalTrees n + | n `mod` 2 == 0 = [] + | otherwise = [Branch 'x' x (reverseTree x) | x <- cbalTree (n `div` 2)] + +reverseTree Empty = Empty +reverseTree (Branch x l r) = Branch x (reverseTree r) (reverseTree l) + +symCbalTrees' = filter symmetric . cbalTree |