Skip to content

Commit

Permalink
62
Browse files Browse the repository at this point in the history
  • Loading branch information
tianyicui committed Dec 2, 2010
1 parent db46b7d commit 07e7747
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions BinaryTrees.hs
Expand Up @@ -92,3 +92,11 @@ hbalTreeNodes n =
countLeaves Empty = 0
countLeaves (Branch _ Empty Empty) = 1
countLeaves (Branch _ l r ) = countLeaves l + countLeaves r

leaves Empty = []
leaves (Branch x Empty Empty) = [x]
leaves (Branch _ left right) = leaves left ++ leaves right

internals Empty = []
internals (Branch _ Empty Empty) = []
internals (Branch x left right) = x : (internals left ++ internals right)

0 comments on commit 07e7747

Please sign in to comment.