int maxDepth(struct node* root)
{
int leftDepth = 0;
int rightDepth = 0;
if (root==NULL)
{
return 0;
}
else
{
leftDepth = maxDepth(root->left);
rightDepth = maxDepth(root->right);
if (leftDepth > rightDepth)
return(leftDepth+1);
else
return(rightDepth+1);
}
}
{
int leftDepth = 0;
int rightDepth = 0;
if (root==NULL)
{
return 0;
}
else
{
leftDepth = maxDepth(root->left);
rightDepth = maxDepth(root->right);
if (leftDepth > rightDepth)
return(leftDepth+1);
else
return(rightDepth+1);
}
}
No comments:
Post a Comment