My doubt is that there is some problem popping up in my code which works perfectly fine on eclipse but not on coding blocks IDE. I think there is some issue in the java. util libraries or the Scanner class. The following is my code. The question is to count the number of nodes in the given binary tree
Binary Tree Height Calculation
In your countnode method, return the subtree with maximum depth.
Instead of: return 1 + lcount + rcount;
Use: return 1 Math.max(lcount,rcount);
Since we need to height, the height will be the max depth of the tree possible.
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.