Tell us what’s happening:
what exactly should I pass in the inorder method for successful recursion?
Your code so far
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;
// Only change code below this line
this.inorder = [];
this.inorder = function(root){
if(this.root === null) return null;
if(root.left) this.inorder(root.left);
this.inorder.push(root.value);
if(root.right) this.inorder(root.right);
return this.inorder;
}
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
.
Challenge: Use Depth First Search in a Binary Search Tree
Link to the challenge: