Discuss Distance between root and leaf. in the C Programming forum on Dev Shed. Distance between root and leaf. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
Time spent in forums: 4 h 47 m 23 sec
Reputation Power: 0
There is really no attitude! I see it this way, not only is this a very simple, straightforward question which should certainly not consume much time, but there are enough qualified people on both forums together to provide answers to all questions. It is rather rare that a question is left unanswered, and if it so happens it is even far more rare that it is because someone posted a simple question like mine elsewhere. If it means that much to you, I could remove it. But please note that I find this somewhat unnecessary and petty (no offense).
Time spent in forums: 1 Day 8 h 58 m 5 sec
Reputation Power: 18
Just thinking. At the root, you got depth = 0. You ask dept from left, how far from leaf it is. You ask the right too. Somewhere is your leaf...If found, return 1 and plus 1 for founder.
if ( leaf found) return 1
left_depth = 0
if (left_node !=NULL)
d = howdepth( left_node, leaft)
if (d >0 )
left_depth = 1+d
right_depth = 0
if ( right_node !=NULL)
d = howdepth( right_node, leaft)
if (d >0)
right_depth = 1+d
depth = max(left_depth, right_depth)