not able to create tree from the input . please tell how to stop the loop from infinite loop
Input for the tree (mirror tree )
hello @Vishal_234
logic is to do a level order traversal .
node * construct(){
node *root=NULL;
int data;
cin>>data;
if(data==-1){
return root;
}
root=new node(data);
queue<node *> q;
q.push(root);
while(!q.empty()){
node * t=q.front();
q.pop();
int d1,d2;
cin>>d1>>d2;
if(d1!=-1){
t->left=new node(d1);
q.push(t->left);
}
if(d2!=-1){
t->right=new node(d2);
q.push(t->right);
}
}
return root;
}