--Problem 56: Symmetric binary trees.
--Let us call a binary tree symmetric if you can draw a vertical line through the root Branch and then the right subtree is the mirror image of the left subtree.
--Write a predicate symmetric/1 to check whether a given binary tree is symmetric.
isSymmTree :: Tree a -> Bool
isSymmTree x = isEqTree x $ invertTree x where
  invertTree :: Tree a -> Tree a
  invertTree Empty = Empty
  invertTree (Branch n y z) = Branch n (invertTree z) (invertTree y)
  isEqTree :: Tree a -> Tree b -> Bool
  isEqTree Empty Empty = True
  isEqTree Empty Branch {} = False
  isEqTree Branch {} Empty = False
  isEqTree (Branch _ a b) (Branch _ c d) = isEqTree a c && isEqTree b d

--Problem 57: Binary search trees (dictionaries).
--Write a predicate to construct a binary search tree from a list of integer numbers.
isSymmTree :: Tree a -> Bool
isSymmTree x = isEqTree x $ invertTree x where
  invertTree :: Tree a -> Tree a
  invertTree Empty = Empty
  invertTree (Branch n y z) = Branch n (invertTree z) (invertTree y)
  isEqTree :: Tree a -> Tree b -> Bool
  isEqTree Empty Empty = True
  isEqTree Empty Branch {} = False
  isEqTree Branch {} Empty = False
  isEqTree (Branch _ a b) (Branch _ c d) = isEqTree a c && isEqTree b d

--Problem 57: Binary search trees (dictionaries).
--Write a predicate to construct a binary search tree from a list of integer numbers.
isSymmTree x = isEqTree x $ invertTree x where
  invertTree :: Tree a -> Tree a
  invertTree Empty = Empty
  invertTree (Branch n y z) = Branch n (invertTree z) (invertTree y)
  isEqTree :: Tree a -> Tree b -> Bool
  isEqTree Empty Empty = True
  isEqTree Empty Branch {} = False
  isEqTree Branch {} Empty = False
  isEqTree (Branch _ a b) (Branch _ c d) = isEqTree a c && isEqTree b d

--Problem 57: Binary search trees (dictionaries).
--Write a predicate to construct a binary search tree from a list of integer numbers.