Getting segmentation fault error

Why this code is not giving output ??

#include
#include
using namespace std;

class node
{
public:
string data;
nodeleft;
node
right;

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

};

node *buildtree()
{
string d;
cin>>d;

if (d=="false")
{
    return NULL;
}

node *root=new node(d);
root->left=buildtree();
root->right=buildtree();

return root;

}

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

int main()
{
node *root1=buildtree();
node *root2=buildtree();
bool ans;
ans=check(root1,root2);
cout<<ans;

return 0;

}

hi @Krishna-Kumar-1362299170640596 your build function is not correct. First you have to take input for root node and then you’ll take input string for left child, build tree for left child and then take input for right child…
Right now, you are expecting that the first input will also be a string. (hint: if first string is not given then you can assume it to be “true” yourself)

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.