Created
July 22, 2014 15:58
-
-
Save satveersm/dde2e8974cb924600197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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