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

C++ 46. 11. Following problems are forthe Binaru Tree data structure with templa

ID: 3848683 • Letter: C

Question

C++ 46. 11. Following problems are forthe Binaru Tree data structure with template. Read the problem carefully and answer them. Following codes are parts of binaryTree for deleting a node. template c To class binaryTree private: truct tree Node T value: The value in the node tree Node left: Pointer to left child node tree Node .right: Pointer to right child node treeNode .root Pointer to the root node void insert (treeNode .R, t Node .a): Private member functions void destroysubTree Ctreekode void deleteNodeCT, tree Node .&); Public binary Tree root NULL; -binary Tree C) destroy SubTree (root): void insertNode(T) bool search Node (T) remove(int value reeNode tree Node void display InOrder CtreeNode consti void display const void displayPostorderctreeNode const void itserativePreorder (treeNode e) const template cclass T> void binaryTreevalue, this); else if t- left this) (parent Parent- left (left 1- NULL) left right: return this: else if (parent->right this) parent-right (left NULL) left right; return this;

Explanation / Answer

//it is member function of class binaryTree node
//this functions counts the number of nodes in a tree.. and returns the count
int binaryTree<T>:: Count_Nodes(treeNode<T> *tree)
{
   static int count=0;//whhich is used to count, through all the function calls
   if(tree!=NULL)//means there is node
   {
       //so..incrementing count
       count++;
       if(tree->left!=NULL)//means there is left node
       {
           Count_Nodes(tree->left);//moving to left sub tree, to count nodes in left sub tree
       }
       if(tree->right!=NULL)//means there is right node
       {
           Count_Nodes(tree->right);//moving to left sub tree, to count nodes in right sub tree  
       }
      
   }
   return count;//returning count...
}