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

solution please Tree Functions 1. Write the definition of the function, nodeCoun

ID: 3533838 • Letter: S

Question

solution please



Tree Functions

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

Explanation / Answer

A function is a special relationship between values: Each of its input values gives back exactly one output value.

It is often written as "f(x)" where x is the value you give it.

Example:

f(x) = x/2 ("f of x is x divided by 2") is a function, because for every value of "x" you get another value "x/2", so:

* f(2) = 1
* f(16) = 8
* f(-10) = -5