no compilation error but multiple test cases failed
Test cases failed https://ide.codingblocks.com/s/663245
hi @abhishekchoudhary05112000_e0b1866595b5a9d4
Have a look at this code–>
#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node*left;
node*right;
node(int d){
data=d;
left=right=NULL;
}
};
void buildTree(node*&root){
string left,right;
int d;
cin>>d;
root = new node(d);
cin>>left;
if(left == "true"){
buildTree(root->left);
}
cin>>right;
if(right == "true"){
buildTree(root->right);
}
}
bool areIdentical(node* root1,node* root2){
if(root1==NULL and root2==NULL)
return true;
return (root1 && root2) && areIdentical(root1->left,root2->left) && areIdentical(root1->right,root2->right);
}
int main() {
node* root1=NULL;
node* root2=NULL;
buildTree(root1);
buildTree(root2);
if(areIdentical(root1,root2)){
cout<<"true"<<endl;
}else{
cout<<"false"<<endl;
}
return 0;
}
You have to print “true”, “false” like this
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.