But hum isme last element kaise print kara rhe hai jbki saare ellements print hone chaiaye uss evel ki keval last element ke liye har ek level ke liye kaise print hoga

but hum isme last element kaise print kara rhe hai jbki saare ellements print hone chaiaye uss evel ki keval last element ke liye har ek level ke liye kaise print hoga

@Aditya-Kushwaha-914550392281281 hey basically right view mtlb,right se agr dekhoge to kaun kuaun si node visible hogi,accr to code:
void rightViewUtil( struct Node *root,

int level, int *max_level)

{

// Base Case

if (root == NULL) return ;

// If this is the last Node of its level

if (*max_level < level)

{

cout << root->data << "\t" ;

*max_level = level;

}

// Recur for right subtree first,

// then left subtree

rightViewUtil(root->right, level + 1, max_level);

rightViewUtil(root->left, level + 1, max_level);

}


We are printing only right mode code when hmara level max level se bda hoga ,ye tabhi hogha jab hm nye level pr jayenge aur jaise hi gye uske pehla element print hojayega,as hm right recursion pehle call krrhe hai to right se pehla hoga,do dry run pls ,you will get it.

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.