My code is giving correct answer for sample case in Code::Blocks ide but not in codingblocks ide(Maybe cause due to difference in compiler). Pls help up with my code. LINK -> https://ide.codingblocks.com/s/149227
Problem in Print BST keys in the given range
Saurabh, firstly your tree is not getting build correctly, so simply take the data from 0 to n, and not from 1 to n, and then use buildtree function in following manner,
if(root==NULL)
{
return new node(data);
}
if(data<=root->data)
{
root->left=insertInBST(root->left,data);
}
else
{
root->right=insertInBST(root->right,data);
}
and secondly you are not using withinrange function correctly,
use these conditions in your code,
if(k1data)
{
inorder(root->left,k1,k2);
}
if(k1<=root->data && k2>=root->data)
{
cout<data<<" ";
}
if(k2>root->data)
{
inorder(root->right,k1,k2);
}