From 897055910d8bda98b3454b6f66ad697edc4676b3 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Sun, 5 Apr 2015 21:22:20 +0800 Subject: +57 +58 --- H55.hs | 1 + H56.hs | 1 + H57.hs | 11 +++++++++++ H58.hs | 12 ++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 H57.hs create mode 100644 H58.hs diff --git a/H55.hs b/H55.hs index a6e6a95..67e2bbb 100644 --- a/H55.hs +++ b/H55.hs @@ -1,3 +1,4 @@ +module H55 where import Tree cbalTree :: Int -> [Tree Char] diff --git a/H56.hs b/H56.hs index 3cf7127..c7960f4 100644 --- a/H56.hs +++ b/H56.hs @@ -1,3 +1,4 @@ +module H56 where import Tree mirror :: Tree a -> Tree a -> Bool diff --git a/H57.hs b/H57.hs new file mode 100644 index 0000000..0af879f --- /dev/null +++ b/H57.hs @@ -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 diff --git a/H58.hs b/H58.hs new file mode 100644 index 0000000..2176997 --- /dev/null +++ b/H58.hs @@ -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 -- cgit v1.2.3-70-g09d2