-
-
Save y-yu/4110254 to your computer and use it in GitHub Desktop.
3.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type 'a tree = Lf | Br of 'a * 'a tree * 'a tree;; | |
let rec height t = | |
match t with | |
Lf -> 1 | |
| Br (_, t1, t2) -> | |
if (height t1) > (height t2) then | |
1 + (height t1) | |
else | |
1 + (height t2);; | |
let rec balance t = | |
match t with | |
Lf -> Lf | |
| Br (_, t1, t2) -> | |
Br ((height t1) - (height t2), balance t1, balance t2);; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment