How can I convert that so that it could match with the input that is also handle true and false;
How can I convert that
Hey, regarding the input:-
If you will carefully analyse,
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
Here 10 means it is root, true after it means that you have left child of 10 , data of tht is 20,
true again means you have left child of 20, which is 40, false means 40 doesnt have left child, again false means that 40 doesnt have right child, true means that 50 is the right child of 20, and like this your tree will be builded
Yes Mam That I understood, But I am not able to think about the input i.e. how I should go for this kinda input. I am also thinking like we can have input d and if the input will be false then it d==0 and condition like if(d==0) return NULL; and if the input is true, I can input it in d and then d will be 1 and can run like if(d!=0) and then follow the other conditions.
Mam I have also made some changes in the code and also commented it. So Please help me for that. Check Comments and tell if my approach is correct, if not please tell.
Hey check this out:
` node* buildBinaryTree()
{
int d;
cin>>d;
node* root = new node(d);
string b;
cin>>b;
if(b == "true")
root->left = buildBinaryTree();
cin>>b;
if(b == "true")
root->right = buildBinaryTree();
return root;
}`
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.