Created
June 22, 2018 23:02
-
-
Save kennetpostigo/9497e2196848ad59b7af884f63c14673 to your computer and use it in GitHub Desktop.
Reason BST Blog Post insert
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
let rec insert = (tree, compare, v) => | |
switch (tree) { | |
| Empty => Node({value: v, left: Empty, right: Empty}) | |
| Node({value, left, right}) => | |
if (compare(v, value) == (-1)) { | |
Node({value, left: insert(left, compare, v), right}); | |
} else if (compare(v, value) == 1) { | |
Node({value, left, right: insert(right, compare, v)}); | |
} else { | |
tree; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment