BST.prototype.insert = function(data) {
var n = new this._Node(data, null, null);
if (this.root === null) {
this.root = n;
} else {
var current = this.root;
var parent;
while (true) {
parent = current;
if (data < current.data) {
current = current.left;
if (current === null) {
parent.left = n;
break;
}
} else {
current = current.right;
if (current === null) {
parent.right = n;
break;
}
}
}
}
};
/**
* Represents a Binary Search Tree
* @constructor
*/
var BST = function() {
this.root = null;
/**
* Node represents a node in the binary search tree
* @constructor
* @param data - the value
* @param left - left side
* @param right - right side
*/
this._Node = function(data, left, right) {
this.data = data;
this.left = left;
this.right = right;
};
};
It has been really great meeting and working with all of you this month. A couple of you have asked for my contact info. Here ya go!
benjamin.hrach@gmail.com
linkedin.com/in/bhrach
And of course you can always find me on Gitter :-)