Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created June 5, 2018 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shameemreza/28b1954c10888d880820c6d6a33c0057 to your computer and use it in GitHub Desktop.
Save shameemreza/28b1954c10888d880820c6d6a33c0057 to your computer and use it in GitHub Desktop.
// 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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment