@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