Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4) A binary tree class uses the BSTNode<T> class for its nodes and has one field

ID: 3630743 • Letter: 4

Question

4) A binary tree class uses the BSTNode<T> class for its nodes and has one field:
              private BSTNode<T> root;
Write a method for this class which returns the number of nodes in the tree. (You may, write two methods where one calls the other to accomplish this.)


The following class is used in problems 4.

public class BSTNode<T extends Comparable<T>>
{
private T data;
private BSTNode<T> left = null, right = null;

public BSTNode(T data)
{
this.data = data;
}//end of method
 // public get and set methods are here
 // for the three fields
}//end of class

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote