#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??