How to take input

plz write the code of build tree.

You can do something like this:

node * buildTree()
{
string d;
cin>>d;
if(d==“false”)
{
return NULL;
}
node * root=new node(stoi(d));
root->left=preorder_input(root->left);
root->right=preorder_input(root->right);
return root;
}

But first we enter integer like 10 true 20 true then how can we compare 10==false?

Yeah…sorry…
do something like this:

node* buildtree(node* root)
{
    int d;
    cin>>d;
    if(!root)
    {
    root=new node(d);}
    string s;
    cin>>s;
    if(s=="true")
    {
        root->left=buildtree(root->left);
    }
    cin>>s;
    if(s=="true"){
        root->right=buildtree(root->right);
    }
    return root;  
}
1 Like

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.