Sfoglia il codice sorgente

Add the function to compute height of a binary tree

DricomDragon 5 anni fa
parent
commit
354f692377
1 ha cambiato i file con 4 aggiunte e 0 eliminazioni
  1. 4 0
      tree.hs

+ 4 - 0
tree.hs

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