summaryrefslogtreecommitdiff
path: root/54a-60/57.hs
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2017-05-29 22:25:03 -0400
committerDeterminant <ted.sybil@gmail.com>2017-05-29 22:25:03 -0400
commit8ea7effa639a0640b38917a9f575aedebcdd2b78 (patch)
tree7916f64813dc89459ae62add344778fedafb3872 /54a-60/57.hs
parentd0aa856bedb0c0223b4ce2a67f5582b8eadf3682 (diff)
finish v6
Diffstat (limited to '54a-60/57.hs')
-rw-r--r--54a-60/57.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/54a-60/57.hs b/54a-60/57.hs
new file mode 100644
index 0000000..efe8588
--- /dev/null
+++ b/54a-60/57.hs
@@ -0,0 +1,23 @@
+import Data.List (foldl')
+
+data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq)
+
+symmetric :: (Eq a) => Tree a -> Bool
+mirror :: (Eq a) => Tree a -> Tree a -> Bool
+
+mirror Empty Empty = True
+mirror (Branch _ a b) (Branch _ l r) = mirror a r && mirror b l
+mirror _ _ = False
+
+symmetric Empty = True
+symmetric (Branch _ l r) = mirror l r
+
+construct :: [Int] -> Tree Int
+addNode :: Tree Int -> Int -> Tree Int
+
+addNode Empty n = Branch n Empty Empty -- create node
+addNode (Branch x l r) n
+ | n <= x = Branch x (addNode l n) r
+ | otherwise = Branch x l (addNode r n)
+
+construct l = foldl' (\acc n -> addNode acc n) Empty l