Question: C++ chapter 19 Binary Trees 1. Write the definition of the function, nodeCount, that returns the number of nodes in the binary tree. Add this

C++ chapter 19 Binary Trees

1. Write the definition of the function, nodeCount, that returns the number of nodes in the binary tree. Add this function to the class 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 theclass binaryTreeType and create a program to test this function.

3. Write a 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.

Complete Programming Exercise 1, 2, and 3. The exercises yield to one solution. Use the test scenario I have included below to test your program. Take a screenshot of your output and include it with your solution.

The output should be like below:

The sample of Output

Enter the element ending with -1

9

6

2

4

98

5

5

The item to be inserted is already in the tree - - duplicate are not allowed.

96

-1

The elements in the order:2 3 4 5 9 96 98

The number of nodes in the binary tree:8

The number of leaves in the binary tree:2

The tree height is 6

After swapping subtrees the tree elements i n order:98 96 9 6 5 4 3 2

Tree height: 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!