Procházet zdrojové kódy

Add the function to compute height of a binary tree

DricomDragon před 5 roky
rodič
revize
354f692377
1 změnil soubory, kde provedl 4 přidání a 0 odebrání
  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)
+