diff --git a/binary_search_tree/bst.cpp b/binary_search_tree/bst.cpp new file mode 100644 index 00000000..d7aa96a4 --- /dev/null +++ b/binary_search_tree/bst.cpp @@ -0,0 +1,14 @@ +// C function to search a given key in a given BST +struct node* search(struct node* root, int key) +{ + // Base Cases: root is null or key is present at root + if (root == NULL || root->key == key) + return root; + + // Key is greater than root's key + if (root->key < key) + return search(root->right, key); + + // Key is smaller than root's key + return search(root->left, key); +} \ No newline at end of file