MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / BST

Class BST

binary-trees/min-heigth-bst.js:16–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16class BST {
17 constructor(value) {
18 this.value = value;
19 this.left = null;
20 this.right = null;
21 }
22
23 insert(value) {
24 if (value < this.value) {
25 if (this.left === null) {
26 this.left = new BST(value);
27 } else {
28 this.left.insert(value);
29 }
30 } else {
31 if (this.right === null) {
32 this.right = new BST(value);
33 } else {
34 this.right.insert(value);
35 }
36 }
37 }
38}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected