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

CSC 240 PA5 Working with Binary Trees Write the definitions of the member functi

ID: 3917579 • Letter: C

Question

CSC 240
PA5 Working with Binary Trees
Write the definitions of the member functions nodeCount() and leavesCount() that return the number of
nodes and leaves, respectively, in the binary tree of type binaryTreeType . See the ToDo sections in
binaryTree.h . This is the only file you should modify and submit. You should compile the main.cpp
provided, in the presence of the binarySearchTree.h that is provided, as well as your modified
binaryTree.h .
Each of these two (template) functions should take as a parameter a pointer to a node of a binary tree, and
return an integer. One of them still needs to be added to the class.
Do not alter the functions treeNodeCount() or treeLeavesCount()--they are wrappers that merely call your
functions. While your functions can theoretically perform the counts on a subtree, the wrapper calls yours
passing the root node pointer, ensuring that the full tree will be counted.
Chapter 19 discusses binary trees at length.
Sample Run:
Enter integers ending with -999
65 55 22 44 61 19 40 10 18 52 -999
Tree nodes in inorder: 10 18 19 22 40 44 52 55 61 65
Tree nodes in preorder: 65 55 22 19 10 18 44 40 52 61
Tree nodes in postorder: 18 10 19 40 52 44 22 61 55 65
Tree Height: 6
Number of Nodes: 10
Number of Leaves: 4
(after Malik, C++ Programming: Program Design Including Data Structures, 7E)

----------------------------------------------binaryTree.h(Edit this one)----------------------------------------------------

-------------------------------------------------binarySearchTree.h------------------------------------------------------

----------------------------------------------------main.cpp--------------------------------------------

Explanation / Answer

OUTPUT