Wednesday 8 August 2012

Count the number of elements in a binary tree.


int count(node *r)
{
      if(r==NULL)
            return 0;
      else
      {
            int c=1;
            c+=count(r->left);
            c+=count(r->right);
            return c;
      }

}

No comments:

Post a Comment