Explore BrainMass

Explore BrainMass

    C++ ordered binary tree: inorder, preorder, postorder

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write a C++ program to read in a set of numbers from an input file and build an ordered binary tree. For this tree, compute and print the following.

    a. Print out the tree in inorder.
    b. Print out the tree in preorder.
    c. Print out the tree in postorder.
    d. Print out the number of nodes in the tree. (Traverse the tree and count the nodes.)
    e. Sum up all the values in the tree and compute the average.
    f. Count the number of leaves in the tree.
    g. Print the value that is the deepest in the tree.

    Input file is named as "TreeData.dat".

    I am stuck on this binary tree program. I have attached my code and data file.

    © BrainMass Inc. brainmass.com October 10, 2019, 6:14 am ad1c9bdddf


    Solution Preview

    Please find attached 535630.cpp that shows how recursion can be used to implement almost every function used in the code to accomplish the given tasks. If you notice carefully, you will see that many of these functions are ...

    Solution Summary

    Solution shows how recursion can be used to accomplish the given tasks. Recursion makes it easy to understand what is going on, apart from neat looking and compact code.