From f9d50917e14ad6817f61bae82376448a45b2bfd3 Mon Sep 17 00:00:00 2001 From: Anshul Gautam <40620896+anshul17024@users.noreply.github.com> Date: Thu, 3 Oct 2019 01:04:00 +0530 Subject: [PATCH] BST insertion --- binary_search_tree/bst.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 binary_search_tree/bst.cpp 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