Find the Minimum and Maximum Value in a Binary Search Tree
Without values I cannot to test the return value. I needed to write “blindly” this code…
and somethings are wrong because fails on the test. I have no idea how can I test the code without values…
var displayTree = tree => console.log(JSON.stringify(tree, null, 2));
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
// change code below this line
this.findMin = function() {
if (!(this.root)) return null;
const node = this.root;
while (node.left) {
node = node.left;
}
return node.value;
};
this.findMax = function() {
if (!(this.root)) return null;
const node = this.value;
while (node.right) {
node = node.right;
}
return node.value;
};
// change code above this line
}