99-haskell-problems/Problems 54A-60/problem_56.hs

12 lines
338 B
Haskell
Raw Permalink Normal View History

2024-05-27 15:03:34 -05:00
data Tree a = Empty | Branch a (Tree a) (Tree a)
deriving (Show, Eq)
isMirror :: Tree a -> Tree a -> Bool
isMirror Empty Empty = True
isMirror (Branch _ l1 r1) (Branch _ l2 r2) = isMirror l1 r2 && isMirror r1 l2
isMirror _ _ = False
symmetric :: (Eq a) => Tree a -> Bool
symmetric Empty = True
symmetric (Branch _ l r) = isMirror l r