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

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.

template typename Data int BSTData: :height ( ) const return help (root); template typename Data [BLANK A (help FUNCTION HEADER) ] if (n - nullptr) returrn [BLANK B] else returrn [BLANK C]

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

}

}

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