Structurally identical

#include
#include
using namespace std;

class node
{
public:
int data;
node *left;
node *right;

node(int d)
{
    data = d;
    left = NULL;
    right = NULL;
}

};

node *build(string s)
{
if (s == “true”)
{
int d;
cin >> d;
node *root = new node(d);
string l;
cin >> l;
if (l == “true”)
{
root->left = build(l);
}
string r;
cin >> r;
if (r == “true”)
{
root->right = build®;
}
return root;
}
return NULL;
}

bool check(node *root1,node *root2)
{
if(root1==NULL && root2==NULL)
return true;
if(root1==NULL || root2==NULL)
return false;
bool b1=check(root1->left,root2->left);
bool b2=check(root1->right,root2->right);
if(root1->data!=root2->data)
return false;
return b1 && b2;
}

int main()
{
node *root1= build(“true”);
node *root2=build(“true”);
if(root1==NULL && root2==NULL)
cout<<“false”;
else
{
if(check(root1,root2))
cout<<“true”;
else
cout<<“false”;

}

return 0;

}
why it is fails for one test case??

hello @sdevesh29
In this problem we only want to compare structure of the two given tree so dont compare their data.

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.