Created
November 19, 2012 12:08
-
-
Save VienosNotes/4110334 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| let rec balance (t:'a tree) : int tree = | |
| let rec height t = | |
| match t with | |
| | Br(_,left,right) -> | |
| let (hl, hr) = (height left, height right) in | |
| if (hl > hr) then hl + 1 else hr + 1 | |
| | _ -> 0 | |
| in | |
| match t with | |
| | Br(value, left, right) -> Br(height left - height right, balance left, balance right) | |
| | Lf -> Lf | |
| ;; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment