예제 #1
0
  int BinarySearchTree::int_path_length(BinaryNode *t, int depth)
 {
  // Your code here
    int d = depth;
    if(t->left != NULL)
       d = d + int_path_length(t->left, depth+1);
    if(t->right != NULL)
       d = d + int_path_length(t->right, depth+1);
    return d;// remove after writing your code
 }
예제 #2
0
int AvlTree::int_path_length(AvlNode *t, int depth) {
    int num = 0;
    if (t == NULL) {
        return depth;
    }
    if (t->left != NULL) {
        num += int_path_length(t->left, depth+1);
    }
    if(t->right != NULL) {
        num += int_path_length(t->right, depth+1);
    }
    // }

    return num+depth; // put your actual return value here when you write this function
}
예제 #3
0
int BinarySearchTree::int_path_length(BinaryNode *t, int depth) {
    // Your code here
  int num = 0;
  if (t == NULL){
    return depth;
  }
  if (t->left != NULL){
  num += int_path_length(t->left, depth+1);
  }
  if(t->right != NULL){
  num += int_path_length(t->right, depth+1);
  }
  // }
  
    return num+depth;
}
예제 #4
0
double AvlTree::exp_path_length( )
/*
**  Calculate the expected path length of the tree
**  This is the public version, without a parameter.
*/
{
    // YOUR CODE HERE
    return (double)int_path_length(root, 0)/(double)num_nodes;  // stub, remove after writing your code
}
예제 #5
0
double BinarySearchTree::exp_path_length( )
/*
**  Calculate the expected path length of the tree
**  This is the public version, without a parameter.
**  NOTE that it recursively invokes int_path_length()
*/
{
    // YOUR CODE HERE
    return (double)int_path_length(root, 0)/(double)num_nodes; // stub, remove after writing your code
}