Write a client method that returns a count of the number of nodes in a binary se
ID: 3758892 • Letter: W
Question
Write a client method that returns a count of the number of nodes in a binary search tree that contain a value less than or equal to the argument value. The signature of the method is: int countLess(BinarySearchTree tree, Golfer maxValue) Write a client method that returns a count of the number of nodes in a binary search tree that contain a value less than or equal to the argument value. The signature of the method is: int countLess(BinarySearchTree tree, Golfer maxValue) Write a client method that returns a count of the number of nodes in a binary search tree that contain a value less than or equal to the argument value. The signature of the method is: int countLess(BinarySearchTree tree, Golfer maxValue)Explanation / Answer
// Since I don't have the details of Golfer class, I'll take maxValue just as a simple integer variable.
/*
I am assuming the structure BinarySearchTree as follows:
BinarySearchTree{
int data;
BinarySearchTree *left;
BinarySearchTree *right;
};
*/
int countLess(BinarySearchTree tree, int maxValue){
if(tree == NULL){
return 0;
}
else{
int x = 0;
if(tree.data < maxValue) x = 1;
return x + countLess(tree.left) + countLess(tree.right);
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.