From 42acb171bc53d501cfabea9f73427aaac44b08d9 Mon Sep 17 00:00:00 2001 From: Vanshjin <70649785+Vanshjin@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:20:11 +0530 Subject: [PATCH] binary tree --- binary tree | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 binary tree diff --git a/binary tree b/binary tree new file mode 100644 index 0000000..1b03eff --- /dev/null +++ b/binary tree @@ -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); +}