Code coverage report for lib/dataStructures/binarySearchTree.js

Statements: 100% (19 / 19)      Branches: 100% (8 / 8)      Functions: 100% (5 / 5)      Lines: 100% (17 / 17)      Ignored: none     

All files » lib/dataStructures/ » binarySearchTree.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341   1 91     1 23     1 91 23     68       1 105 51 18   54 19       1     1  
var binarySearchTree = function() {
 
	function getBinaryNode(dataToUse) {
		return { left: null, right: null, data: dataToUse };
	};
 
	function bst() {
		this.head = null;
	}
 
	bst.prototype.add = function(data) {
		if(this.head === null) {
			this.head = getBinaryNode(data);
		}
		else {
			this.insert(this.head, data);
		}
	}
 
	bst.prototype.insert = function(node, data) {
		if(node.data > data ) {
			if (node.left === null) { node.left = getBinaryNode(data); }
			else { this.insert(node.left, data); }
		} else {
			if (node.right === null) { node.right = getBinaryNode(data); }
			else { this.insert(node.right, data); }
		}
	}
 
	return bst;
}
 
module.exports = binarySearchTree();