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 }
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 }
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; }
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 }
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 }