why is it not taking inputs and please try to take the bool variables in numbers as custom input
Structurally Identical (Binary Tree)
Hi @sanyamsri2001
Basically the program is not taking input because when you take input of ans remember one thing that when you are entering the input it is a string so when you pass it in function then there the code goes wrong because you are using string instead of bool variable. For handling this you should take input as string and then decide whether to pass 1 or 0 in further function call.
node *buildtree(bool ans){
if(ans){
int data;
string a;
cin>>data;
node *root=new node(data);
cin>>a;
if(a==“true”)
root->left=buildtree(1);
if(a==“false”)
root->left=buildtree(0);
cin>>a;
if(a=="true")
root->right=buildtree(1);
if(a=="false")
root->right=buildtree(0);
return root;
}
else{
return NULL;
}
}
This is how you have to handle the string input and pass the bool variable.