summaryrefslogtreecommitdiff
path: root/54a-60/59.hs
blob: 0faecd6229aec2f65f37207c85cd980f911bb569 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq)

hbalTree :: a -> Int -> [Tree a]

hbalTree x 0 = [Empty]
hbalTree x 1 = [Branch x Empty Empty]
hbalTree x h =
    [Branch x lt rt
      | (h1, h2) <- [(h-2, h-1), (h-1, h-2), (h-1, h-1)]
      , lt <- hbalTree x h1
      , rt <- hbalTree x h2]