Question: A fragment of the source code for a Binary Search Tree (BST) in JavaScript is given down below: class Node { constructor(val){ this.val = val
A fragment of the source code for a Binary Search Tree (BST) in JavaScript is given down below:
class Node { constructor(val){ this.val = val this.left = null this.right = null } } class BST { constructor(){ this.root = new Node(nul1) } insert (val) { this.insert_val(val, this.root) console.log(val + " has been inserted") } insert_val (val, node) { if (node.val null) { == node.val val return } else if (val < node.val) { if (node.left == null) node.left = new Node(null) this.insert_val(val, node.left) } else { if (node.right == null) node.right = new Node(nul1) this.insert_val(val, node.right) } } print_level_order () { if (this.root. val == null) return "Empty tree" let visited = [], queue = [], current = this.root queue.push(current)
Step by Step Solution
3.60 Rating (157 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
