We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8fae46e commit 3475013Copy full SHA for 3475013
src/_DataStructures_/Trees/BST/index.js
@@ -69,6 +69,19 @@ class BinarySearchTree {
69
70
return [...arr, root.value];
71
}
72
+
73
+ search(root, value) {
74
+ if (root === null) return false;
75
+ if (value === root.value) return true;
76
77
+ if (value < root.value) {
78
+ return this.search(root.leftChild, value);
79
+ }
80
+ if (value > root.value) {
81
+ return this.search(root.rightChild, value);
82
83
+ return false;
84
85
86
87
// const bst = new BinarySearchTree(6);
@@ -91,4 +104,7 @@ class BinarySearchTree {
91
104
// const postorder = bst.postorder(bst.root);
92
105
// console.log('Postorder Traversal - ', postorder);
93
106
107
+// const search = 18;
108
+// console.log(`Search for ${search}`, bst.search(bst.root, search));
109
94
110
module.exports = BinarySearchTree;
0 commit comments