Ver código fonte

Add the function to compute height of a binary tree

DricomDragon 5 anos atrás
pai
commit
354f692377
1 arquivos alterados com 4 adições e 0 exclusões
  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)
+