I am getting WA in one test case
Solution link: https://ide.codingblocks.com/s/145537
Tree top view: getting WA in one test case
@17uec133 when printing the top view, we have to first call the recursion for left subt-ree then print the nodes of the left sub-tree. But when print the right sub-tree, first we have to print the node and then we have to call the recursion function. So the rightPrint function should be
void rightPrint(Node* root){
if(root == NULL){
return;
}
cout<data<<" ";
rightPrint(root->right);
}
instead of :
void rightPrint(Node* root){
if(root == NULL){
return;
}rightPrint(root->right); cout<<root->data<<" ";
}
Hope this helps.