Structuraly identical trees

how to build the tree when the input is like this .

node*buidtree(string s){

    if(s=="true"){

    int d;

    cin>>d;

    node*root=new node(d);

    string l;

    cin>>l;

    if(l=="true"){

    root->left=buidtree(l);

    }

    string r;

    cin>>r;

    if(r=="true"){

    root->right=buidtree(r);

    }

    return root;

    }

    return NULL;

}

just pass true during function call

buidtree("true")

Dry run the above with the sample case
You just have to take the input in preorder format
Say 10 true 20 true 40 false false true 50 false false true 30
It means 10 is the root node.
next input is true…so it means a left child is present and its value is 20.
now again after 20, there is a true…which means left child of 20 is present and it is 40.
Now after 40 comes false…which means there is no left child…
Again there is a false…so there is no right child…So you can say now that 40 is a leaf node.
Now…there is a true(you have returned back to node 20)…so right child of 20 is present and its value is 50.
Now comes false twice…which means there is no left child and right child of node 50…
So…in this order you have to proceed and build the tree.