for the given input , i made a code which is not working. can someone tell my mistake in the code.
given input:-
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
Constructing binary tree (given:-pre order)
Mrinali, you are using wrong approach for building a tree, your tree is not getting builded up, thats why the code compiles but doesnt show any output, try using different approach
can you please check this. and if my approach is wrong… then please explain me how to take input
Your code is showing run time error,
You can maintain a string and check
if(str==“true”)
{
cin>>d;
node *temp=new node(d);
temp->left=buildtree(temp->left);
temp->right=buildtree(temp->right);
return temp;
}
else
if(str==“false”)
{
return root;
}