Browse Source

Add the function to compute height of a binary tree

DricomDragon 5 years ago
parent
commit
354f692377
1 changed files with 4 additions and 0 deletions
  1. 4 0
      tree.hs

+ 4 - 0
tree.hs

@@ -1,2 +1,6 @@
 data BinaryTree = Leaf | Node Integer BinaryTree BinaryTree
 
+height bigTree = case bigTree of
+	Leaf -> 0
+	Node _ leftTree rightTree -> 1 + max (height leftTree) (height rightTree)
+