ction nodeCount that returns the his function to the clasa 1. Write the definiti
ID: 3721479 • Letter: C
Question
ction nodeCount that returns the his function to the clasa 1. Write the definition of the fun number of nodes in the binary tree. Add t binaryTreeType and create a program to test this function. 2. Write the definition of the function leavesCount that takes as a parameter a pointer to the root node of a binary tree and returns the number of leaves in a binary tree. Add this function to the class binaryTreeType and create a program to test this function. 3. Write the function swapsubtrees that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function.Explanation / Answer
Hi Friend,
You have not posted the structure of binaryTreeType class, so i can not know the members of the class.
As per the chegg guideline, please post one question per post.
I have answered Q1 in general.
The count nodes function is best for recursion, calling thetrees on the left and right.
int BinaryTreeType::countNodes(Tree *T)
{
if(T == NULL)
return0;
else
return 1+ countNodes(T -> left) + countNodes(T -> right);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.