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

4. Write the lines of code that will generate what is requested in each part. As

ID: 3733454 • Letter: 4

Question

4. Write the lines of code that will generate what is requested in each part. Assume using space std;, that all necessary headers are provided, and abide by good coding name practices. You do not need to include comments for functions. (a) (5 points) Consider the classes BinarySearchTree and TreeNode below. Let BinarySearchTree: :print () be the function that prints the nodes from a bi- nary search tree in order, using the helper recursive function TreeNode: :print nodes () Write both functions print() and print nodes (). You do not need to implement the Bina essary class TreeNode rySearch Tree and TreeNode class but specify any new declarations if nec- private: int data; TreeNodex left; TreeNode* right; J; class BinarySearchTree private: TreeNode* root; 3;

Explanation / Answer

BinarySearchTree :: print(){

root->print_nodes(root);

}

TreeNode :: print_nodes(TreeNode *root){

if (root == NULL)

return;

print_nodes(root->left);

printf(" ");

printf("%d", root->data);

print_nodes(root->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