Wednesday 8 August 2012

calculate the depth of the binary tree.


int maxdepth=0;
void depth(node *r,int d)
{
      if(r!=NULL)
      {
            if(maxdepth<d)
                  maxdepth=d;
            depth(r->left,d+1);
            depth(r->right,d+1);
      }
}

No comments:

Post a Comment