i want to know how to find the height of a binary tree...Hope some one can help ma....thx
i want to know how to find the height of a binary tree...Hope some one can help ma....thx
What have you tried so far? Think about it logically on paper first, then try to write the code. Post it here when you have troubles and someone will help you.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
I have tried to use recursive function to do it,but actually cannot think of a feasible algorithm.Can any one tell me the algorithm of this function, thx a alot
The height of a tree is 1 plus the greater of the heights of the subtrees. That should be a clue on how to implement this recursively:
Code:int TreeHeight( Node* Tree) { if node is NULL return 0; else return 1 plus greater of left/right subtree heights // hint: use recursion here }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Wml:
This is a common tree problem- you could have look it up in text/reference books. Or do a search on the internet!!
Mr. C: Author and Instructor