Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //summing the values in a int binTree
- let rec sum btree =
- match btree with
- | Leaf -> 0
- | Node ( r, left, right ) -> r + sum left + sum right
- // number of nodes
- let rec count btree =
- match btree with
- | Leaf -> 0
- | Node ( r, left, right ) -> 1 + count left + count right
- // depth of a tree
- let rec depth btree =
- match btree with
- | Leaf -> 0
- | Node ( r, left, right ) -> 1 + (max (depth left) ( depth right))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement