Skip to content

Instantly share code, notes, and snippets.

@kennetpostigo
Created June 22, 2018 23:02
Show Gist options
  • Save kennetpostigo/9497e2196848ad59b7af884f63c14673 to your computer and use it in GitHub Desktop.
Save kennetpostigo/9497e2196848ad59b7af884f63c14673 to your computer and use it in GitHub Desktop.
Reason BST Blog Post insert
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