test case(3) is not running please help what i am doing wrong .
One test case is not running
#include<iostream>
#include
#include
using namespace std;
class node{
public:
string data;
nodeleft;
noderight;
node(string d){
data = d;
left = NULL;
right = NULL;
}
};
node buildtree()
{
string d;
cin>>d;
node root;
if(d==“false”)
{
return NULL;
}
if(d==“true”)
{
cin>>d;
}
root = new node(d);
root->left = buildtree();
root->right = buildtree();
return root;
}
void print(node *root,vector &s){
if(root==NULL){
return;
}
//Otherwise, print root first followed by subtrees(children)
s.push_back(root->data);
print(root->left,s);
print(root->right,s);
}
int main() {
node *root1=buildtree();
node *root2=buildtree();
vector s1;
vector s2;
print(root1,s1);
print(root2,s2);
if(s1.size()==s2.size())
{int c=0;
for(int i=0;i<s1.size();i++)
{
if(s1[i]!=s2[i])
{
c=1;
cout<<"false";
break;
}
}
if(c==0)
{
cout<<"true";
}
}
else
{
cout<<"false";
}
return 0;
}
Please, share it using Coding Blocks IDE.
The way you have send has introduced many syntax errors in it.
Steps:
- Open Coding Blocks IDE.
- Paste your code there.
- Save your code.
- Share the URL here.
Hello @S18ML0016,
I guess you have misunderstood the question.
It says structurally identical binary tree.
which there structure should be same, not the values their nodes contain.
Example:
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
Expected Output:
true
Your Output:
true
Now, here comes the problem:
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
10 true 20 true 40 false false true 50 false false true 30 true 53 false false true 73 false false
Expected Output:
true
Your Output:
false
Conclusion: you need not compare the values stored in the node.
Hope, this would help.
Give a like, if you are satisfied.