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

Write a public member function incrementNodes for a BinaryTree class that will a

ID: 3713145 • Letter: W

Question

Write a public member function incrementNodes for a BinaryTree class that will add 1 to each item in the binary tree. If this function calls any other function, you must write the code for that function as well. Note that the class BinaryTree has a private member variable root which is a Node pointer.

Explanation / Answer

#include using namespace std; struct Node { int data; Node *left; Node *right; }; class BinaryTree { private: Node *root; void incrementNodes(Node *temp); public: void incrementNodes(); }; // Below is the code that you need void BinaryTree::incrementNodes() { incrementNodes(root); } void BinaryTree::incrementNodes(Node *temp) { if(temp != NULL) { temp->data += 1; // increment data in node incrementNodes(temp->left); // recursive call to left subtree incrementNodes(temp->right); // recursive call to right subtree } } // Above is the code that you need int main() { return 0; }
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