Skip to content

Instantly share code, notes, and snippets.

@scriptonian
Last active September 5, 2017 15:41
Show Gist options
  • Save scriptonian/e1f1b7ab05aebf5fe9e35b05950a693b to your computer and use it in GitHub Desktop.
Save scriptonian/e1f1b7ab05aebf5fe9e35b05950a693b to your computer and use it in GitHub Desktop.
Adding the BST methods to class. Insert, find, remove, max, min and traversal
//ES5 version
function TreeNode(keyValue) {
this.keyValue = keyValue;
this.left = null;
this.right = null;
this.toString = function() {
return this.keyValue;
}
}
function BinarySearchTree() {
var rootNode = null;
}
BinarySearchTree.prototype = {
insert: function(key) {},
find: function(key) {},
remove: function(key) {},
max: function(){},
min: function() {},
traverse: function(){}
}
//ES2015 & beyond
class TreeNode {
constructor(keyValue) {
this.keyValue = keyValue;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor() {
let root = null;
}
toString() {
return this.keyValue;
}
insert(key) {}
find(key) {}
remove(key) {}
max(){}
min() {}
traverse(){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment