Explorar el Código

Add the function to compute height of a binary tree

DricomDragon hace 5 años
padre
commit
354f692377
Se han modificado 1 ficheros con 4 adiciones y 0 borrados
  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)
+