Created
April 21, 2019 15:28
-
-
Save jdgo-mars/1cac1b8afb22fd7576f5822713130b2d to your computer and use it in GitHub Desktop.
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
function BinarySearchTree(val) { | |
this.value = val; | |
this.left = null; | |
this.right = null; | |
} | |
BinarySearchTree.prototype.insert = function(value) { | |
let subtree = value < this.value ? 'left' : 'right'; | |
if (this[subtree]) { | |
this[subtree].insert(value); | |
} else { | |
this[subtree] = new BinarySearchTree(value); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment