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

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

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


Get Latest JobsAdda.com Jobs, news & updates  via Email