My one testcase is not passing in this can you correct my code and mention the testcase where my code might be failing and comment the changes in my code.
Here is my code: https://ide.codingblocks.com/s/252865
My one testcase is not passing in this can you correct my code and mention the testcase where my code might be failing and comment the changes in my code.
Here is my code: https://ide.codingblocks.com/s/252865
there is some issue with the buildTree function of urs
the tree is not correctly formed
node* buildtree(){
int d;
cin>>d;
node*root=new node(d);
queue<node*> q;
q.push(root);
while(!q.empty()){
node*f=q.front();
q.pop();
int c1,c2;
cin>>c1>>c2;
if(c1!=-1){
f->left=new node(c1);
q.push(f->left);
}
if(c2!=-1){
f->right=new node(c2);
q.push(f->right);
}
}
return root;
}
eg: i/p
1 2 3 4 5 -1 6 -1 -1 -1 -1 7 -1 -1 -1
should give answer
1 2 4 7
ur code gives 1 2 4