getting teset cases wrong
Tree right view
Faizan, the approach you are using is not correct,
You can use the following approach in your code as,
You can take a rightview function as, :
void rightview(node *root)
{
int max_level=0;
rightutil(root,1,&max_level);
}
And based on this you will have a rightutil function as,
void rightutil(node *root,int level,int *max_level)
{
if(root==NULL)
{
return;
}
if(*max_level<level)
{
cout<data<<" ";
*max_level=level;
}
rightutil(root->right,level+1,max_level);
rightutil(root->left,level+1,max_level);
}
Hope you understood this approach…
1 Like