Finish the code shown below to calculate and return the height method for the BS
ID: 3596960 • Letter: F
Question
Finish the code shown below to calculate and return the height method for the BST class declared above. You may not
assume you have a variable that already stores the height. As in PA1, an empty tree has height -1, and a tree with one node has height 0.
You are adding the necessary code to the help function, which takes one argument named n (you must determine its type). Note that you might find the std::max function helpful, which returns the maximum of two arguments. E.g. std::max(3, 7) returns 7.
Explanation / Answer
template <typename Data>
int BST<Data>::help(BST<Data> n) {
if(n==nullptr) {
return -1;
} else {
return std::max(1 + help(n.left), 1 + help(n.right));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.