Depth

good solution

int depth(Tnode *root)
{   
    if (root == NULL)
        return 0;
 
    return MAX(depth(root->left), depth(root->right)) + 1;
}

bad solution

int depth2(Tnode *root, int n)
{
    int max;
    if (root == NULL)
        return n;
 
    n++;
    max = MAX(depth2(root->left, n), depth2(root->right, n));
    return max;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License