In the given example, the o/p is 4 2 6 3. I could not understand the explanation provided in braces.
Not able to understand the output
@kodivine0 if you make the tree perfectly 5 and 6 will overlap so you have to take the right one ie 6
in each case we will take right one or does it depend on the value which is greater?
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.
1 last question sir, how should i take the input?
its is level order input
whenever child node has -1 then it is considered null node
node * createtree(){
queue <node *> q;
int data;
node * root=NULL;
cin>>data;
node * temp=NULL;
if(data!=-1){
root=new node(data);
}
q.push(root);
while(!q.empty()){
cin>>data;
if(data!=-1){
temp=new node(data);
q.front()->left=temp;
q.push(temp);
}
cin>>data;
if(data!=-1){
temp=new node(data);
q.front()->right=temp;
q.push(temp);
}
q.pop();
}
return root;
}
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.