[prev] 31 [next]

Tree Size

New functions for determining tree size:

// efficient; use outside Tree-changing functions
int size(Tree t) 
{
   return (t == NULL) ? 0 : t->nnodes;
}
// inefficient; use while making chages to Tree
int count(Tree t)
{
   if (t == NULL)
      return 0;
   else
      return 1 + count(t->left) + count(t->right);
}