here is the link to my code:ide.codingblocks.com/s/210707
please help me i am doing it from past 2 days and now i am annoyed with this question
I don't know why error is coming
Bhavit there are few errors in your code… Pls rectify them…
- The function you are using to build your tree is not correct… PLs use the following approach to build your tree as ,
node* insert(node* root,int data)
{
if(root==NULL)
{
//return newB(d);
return new node(data);
}
if(data<=root->data)
{
root->left=insert(root->left,data);
}
else
{
root->right=insert(root->right,data);
}
return root;
}
- The approach you are trying to use for printing in a given range is also incorrect… Pls use the approach as,
void printbst(node* root,int k1,int k2)
{
if(root==NULL)
{
return;
}
if(k1<root->data)
{
printbst(root->left,k1,k2);
}
if(k1<=root->data && k2>=root->data)
{
cout<<root->data<<" ";
}
if(k2>root->data)
{
printbst(root->right,k1,k2);
}
}