Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: You are given two classes for implementing a simple binary tree of capable of storing number, count the number of leaves and computes the

Objectives:You are given two classes for implementing a simple binary tree of capable of storing number, count the number of leaves and computes the height of a binary tree.

You can add on additional parameters or functions as you wish but the program must apply the chapter objectives.

image text in transcribed
class BTreeNode public: BTreeNode (double x, BTreeNode *leftp - NULL, BTreeNode *rightp = NULL) value = x} left = leftp; right = rightp; } private: double value; BTreeNode "left, "right; friend class BST; // BST has friend status // Binary tree class itself class BST public: int height() { return height (tree); } // return the tree height void insert (double x) ; // insert numbers into the binary tree void inorder(vector & v) { inorder(v, tree); } // appends all nodes in subtree int leafCounter () { return leafCounter (tree); } // count the number of leaves BST() { tree = NULL; } private: void inorder(vector&tlist, BTreeNode *t); // storing nodes in subtree int leafCounter (BTreeNode *t); // count the number of leaves static int height (BTreeNode *t); // calculate the height of the tree BTreeNode *tree; Sample output: This program allows you to insert some numbers in binary search tree. It prints out the numbers in the tree in inorder. It computes and prints the number of leaves in the tree. and the height of the tree. Enter 10 numbers: 8 20 6 4 23 30 29 33 7 45 The items in the tree in inorder are: 4 6 7 8 20 23 29 30 33 45 The height of the tree is 6 The number of leaves is 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions