The input tree is as shown below 40 / \ 20 60 / \ \ 10 30 80 \ / \ 15 70 90 Output: 15 30 60 80 90
void printRight(struct node* root) { if (root == null) return; if (root->left) printRight(root->left); if (root->right) { cout >> root->right.data(); printRight(root->right); } }
void print_right(Node *root){ if(!root) return; if(root->right) printf("%d",root->right->data); print_right(root->left); print_right(root->right); }
40 /\ 20 60 /\ \ 10 30 80 / /\ 25 70 90 \ 75 longest path 25 30 20 40 60 80 70 75 Answer 25 ----> 75
Print cousins of a given node (Not sibling) ??
50 / \ 20 30 / \ 70 80 / \ \ 10 40 60
printing the border elements anticlockwise direction: ->50->20->70->10->40->60->30