title: Function that return average depth of a binary search tree
body: <p>I have the following binary tree structure, and I'd like to write a function that calculates and return the <strong>average depth</strong> of objects in a tree.
  Here is what I'm trying to do: </p>
  
  <ul>
  <li>calculate the total height of the tree</li>
  <li>divide total height/total nodes</li>
  </ul>
  
  <p>However, I'm getting nowhere, and would love to have any helpful suggestions in terms of how can I go about implementing the algorithm.  </p>
  
  <pre><code>typedef struct tree_s tree_t;
  struct tree_s {
      int num;
      tree_t *left;
      tree_t *right;
  }
  
  
  int total_depth(tree_t *tree, int accum) {
      if (tree == NULL) {
          return accum; /* done */
      }
      accum = accum + total_depth(tree-&gt;left, accum+1);
      accum = accum + total_depth(tree-&gt;right, accum+1);
      return accum;
  }
  </code></pre>
  
  <p>There seems to be something wrong with my recursive function total_depth, as i'm getting a ridiculously large number.</p>