lst2Tree xs = process xs Empty where
  insertTree :: (Ord a) => a -> Tree a -> Tree a
  insertTree n Empty = leaf n
  insertTree n (Branch m p q) = if m > n then Branch m (insertTree n p) q else Branch m p (insertTree n q)
  process :: (Ord a) => [a] -> Tree a -> Tree a
  process y a = foldl (flip insertTree) a y

--Problem 58: Generate-and-test paradigm.
--Apply the generate-and-test paradigm to construct all symmetric, completely balanced binary trees with a given number of nodes.
lst2Tree xs = process xs Empty where
  insertTree :: (Ord a) => a -> Tree a -> Tree a
  insertTree n Empty = leaf n
  insertTree n (Branch m p q) = if m > n then Branch m (insertTree n p) q else Branch m p (insertTree n q)
  process :: (Ord a) => [a] -> Tree a -> Tree a
  process y a = foldl (flip insertTree) a y

--Problem 58: Generate-and-test paradigm.
--Apply the generate-and-test paradigm to construct all symmetric, completely balanced binary trees with a given number of nodes.
lst2Tree xs = process xs Empty where
  insertTree :: (Ord a) => a -> Tree a -> Tree a
  insertTree n Empty = leaf n
  insertTree n (Branch m p q) = if m > n then Branch m (insertTree n p) q else Branch m p (insertTree n q)
  process :: (Ord a) => [a] -> Tree a -> Tree a
  process y a = foldl (flip insertTree) a y

--Problem 58: Generate-and-test paradigm.
--Apply the generate-and-test paradigm to construct all symmetric, completely balanced binary trees with a given number of nodes.