Print bst keys in the given range

PRINT BST KEYS IN THE GIVEN RANGE

https://codeshare.io/5wVbBD

Hi @sanyamsri2001
The mistake that you are doing is that you are putting a check in if case but remember one that root might not be in range but its left and right could be in range of a and b so instead put a check when you are printing the root->data this will be your code error free.

void inorder(node *root,int l,int r){
if(root==NULL){
return ;
}
inorder(root->left,l,r);
if(root->data<=r && root->data>=l)
cout<data<<" ";
inorder(root->right,l,r);
}

Suppose you have a as 1 and b as 6, Then according to your code if there is a node with value of 7 you wont be visiting to its left child which could be in range of 1 to 6 hence it was giving wrong output.