Write a C program to compute the maximum depth in a tree?
October 28, 2007 · Filed Under Placement Questions, Tree
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
Here is some C code…
int maxDepth(struct node* node)
{
if (node==NULL)
{
return(0);
}
else
{
int leftDepth = maxDepth(node->left);
int rightDepth = maxDepth(node->right);
if (leftDepth > rightDepth) return(leftDepth+1);
else return(rightDepth+1);
}
}
Related Articles
- Write a C program to compute the maximum depth in a tree?
- Write a C program to find the mininum value in a binary search tree.
- Write a C program to find the mininum value in a binary search tree.
- Write a C program to determine the number of elements (or size) in a tree.
- Write a C program to determine the number of elements (or size) in a tree.


