Skip to content

Instantly share code, notes, and snippets.

@satveersm
Created July 22, 2014 15:58
Show Gist options
  • Save satveersm/dde2e8974cb924600197 to your computer and use it in GitHub Desktop.
Save satveersm/dde2e8974cb924600197 to your computer and use it in GitHub Desktop.
//In A Binary tree how many keys are >= k1 && <= k2
int KeyCount(Node* root,int k1, int k2)
{
if(root == NULL) return 0;
if(root.key < k1) return KeyCount(root->right,k1,k2);
if(root.key > k2) return KeyCount(root->left,k1,k2);
return 1 + KeyCount(root->left,k1,k2) + KeyCount(root->right,k1,k2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment