Structurally identical

Hey the input given in this question is of the form -

10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false

How can I take this input for two tree as there is no marking to indicate that input for first tree has ended and for second it has begun

Hey @Divya_321
Use the fact that the input for the two trees is given in two different lines

I am yet confused how to take input as sometimes inspite of integer it is bool value that I get , there is no uniformity in input , just show me how to take input here

@Divya_321
Here’s the code required:

In the main function:
You’ve to take input to build the tree like this:

int main() {
  
    int data;
    cin>>data;
    node* root1=new node(data);
    root1->left=buildtree();
    root1->right=buildtree();
    int data1;
    cin>>data1;
    node* root2=new node(data1);
    
    root2->left=buildtree();
    root2->right=buildtree();
} 

The buildTree function would go like:
node* buildtree()
{
char check[10];
cin>>check;

	if(strcmp(check,"true")==0)
	{
		
		int data;
		cin>>data;
		node* root=new node(data);
		root->left=buildtree();
		root->right=buildtree();
		return root;
	}
	else
	{
		return NULL;
	}
}

basically for every tree, it’ll take further inputs depending on whether the string after data is true or false, so first tree will auto stop taking inputs, acc to whether the string is true/false

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.