Sir, i have a doubt

Sir, mujhe iss given array(input) ka size nhi pta hai. to m ise kaise kisi array me kaise store kr skta hu ?

hello @chandreshmaurya

tum ko array me store nahi karna hai. balki level order ki help se given tree constrcut karna hai.



node *buildtree() //build tree function to build tree level wise
{
int d;
cin>>d;
queue<node *>q;
node  * root=new node(d);
q.push(root);
int c1,c2;
while(!q.empty())
{
node*  f=q.front();
q.pop();
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;
}

sir, as we know, parent jiska index ‘i’, to uska left children ‘2i+1’ aur right children '2i+2’ index par honge. iss method se m try kar rha hu

…

ha aise bhi kar sakte ho…

but, uske liye given input ko array me store krna pdega. wo m kaise kr skta hu? because, yha pe number of element nhi diya hua hai.

use vector->

sir, I solved it but i’m not getting any output. please have a look ->https://ide.codingblocks.com/s/468654

Sir, please have a look at my code.

…

yeah bro , i m checking ur code only.
there is some bug that i m not able to catch thats why i m taking sometime.
pls try to solve some other problem.
i will ping u back once it get debugged completely

ohkay Sir .

the tree construction method will not work.

for exampe->

       1
           \
            2
              \
               3

its level order will be 1 -1 2 -1 3 -1 -1
and the tree that we construct using this is

     1
         \
          2

the above method will work if we have complete tree for skew tree it fails.

sir, can u please correct

…

u need to change the tree building approach.

use this method.

and in ur print right view function pass marked_level by reference

done sir, Thank You .

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.