Add(value) {
let current = this.root;
if (!current) {
this.root = new Node(value);
}
else {
while (current) {
if (value < current.value) {
if (!current.left) {
current.left = new Node(value);
break;
}
current = current.left;
}
else {
if (!current.right) {
current.right = new Node(value);
break;
}
current = current.right;
}
}
}
}
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)