heyy please check my output is printing in reverse order.
Expected output:
2=>1<=END;
3=>2<=END;
END=>3<=END
My output:
END=>3<=END
3=>2<=END
2=>1<=END
here is my code: https://ide.codingblocks.com/s/194632
heyy please check my output is printing in reverse order.
Expected output:
2=>1<=END;
3=>2<=END;
END=>3<=END
My output:
END=>3<=END
3=>2<=END
2=>1<=END
here is my code: https://ide.codingblocks.com/s/194632
Hey @Aparna
You’re printing the tree in the wrong order
You’re first calling the print function on left and right subtrees through these statements:
nodeleft=print(root->left);
noderight=print(root->right);
and then you’re printing the root, so basically you’re doing postorder printing.
Print it in the preorder way.
First print root and then call for left and right subtree printing.
it seems to be inorder not preorder as the left child prints first then root and right. I have modified it a little but still getting the same output. Please correct it.
@Aparna
What if you write like this?
if(root->left==NULL)
cout<<“END=>”;
else
cout<left->data<<"=>";
cout<data<<"<=";
if(root->right==NULL)
cout<<“END”;
else
cout<right->data;
cout<<endl;
noderight=print(root->right);
nodeleft=print(root->left);
no it doesnt work T.T check my code again
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.