please show me the code for building tree from level order traversal where number of total inputs are unknown.
example:
1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1
How to build tree from level order traversal
@samadsid7 hey abdul this question need a queue to process a level order input.
node* buildTreeLevelWise(){
int d;
cin>>d;
noderoot = 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;
}