Advertisement
Guest User

Untitled

a guest
Apr 20th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.48 KB | None | 0 0
  1.  
  2. //summing the values in a int binTree
  3.  
  4. let rec sum   btree =
  5.     match btree with
  6.         | Leaf -> 0
  7.         | Node ( r, left, right ) -> r + sum left + sum right
  8.  
  9. // number of nodes
  10. let rec count   btree =
  11.     match btree with
  12.         | Leaf -> 0
  13.         | Node ( r, left, right ) -> 1 + count left + count right
  14.  
  15. // depth of a tree
  16. let rec depth   btree =
  17.     match btree with
  18.         | Leaf -> 0
  19.         | Node ( r, left, right ) -> 1 + (max (depth left) ( depth right))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement