Prompt: You are going to write a function that will use recursion to countthe nu
ID: 3611382 • Letter: P
Question
Prompt:You are going to write a function that will use recursion to countthe number of nodes in a tree. Your main program will call a publicmember function called numNodes. This function will then call aprivate member function that will use recursion to count the numberof nodes in the entire tree. I need help making the numNodesfunction and the comments that is in bold. Theanswer to this project is 19 nodes.
#include <iostream>
using namespace std;
class IntBinaryTree
{
private:
struct TreeNode
{
intvalue; // The valuein the node
TreeNode *left; //Pointer to left child node
TreeNode *right; //Pointer to right child node
};
TreeNode *root; //Pointer to the root node
// Private member functions
void insert(TreeNode *&, TreeNode *&);
public:
// Constructor
IntBinaryTree()
{ root = NULL; }
{return numNodes(root);}
void insertNode(int)
// Destructor
//~IntBinaryTree()
//{ destroySubTree(root); }
// Binary tree operations
void insertNode(int);
// bool searchNode(int);
void remove(int);
};
int IntBinaryTree::countNodes(TreeNode *nodePtr)
{
if (nodePtr == NULL)
//write only one lineof code here
return 0;
else
//write only one lineof code here
return(1+count(nodePtr->right), count(nodePtr->left))
}
//void IntBinaryTree::numNode(TreeNode *nodePtr)
void IntBinaryTree:: insertNode(int num)
{
TreeNode *newNode; //Point to a new node.
//Create a new node and store num in it.
newNode = new TreeNode;
newNode->value = num;
newNode->left = newNode->right = Num;
//Insert the node.
insert(root, newNode);
}
int main()
{
IntBinaryTree tree;
tree.insertNode(14);
tree.insertNode(10);
tree.insertNode(8);
tree.insertNode(6);
tree.insertNode(5);
tree.insertNode(7);
tree.insertNode(9);
tree.insertNode(12);
tree.insertNode(11);
tree.insertNode(13);
tree.insertNode(22);
tree.insertNode(30);
tree.insertNode(32);
tree.insertNode(24);
tree.insertNode(20);
tree.insertNode(17);
tree.insertNode(15);
tree.insertNode(18);
tree.insertNode(21);
cout << "The number of nodes in the treeis: " << tree.numNodes() << endl;
system("pause");
return 0;
}