Starting Out With C++, Early Objects - With Access Package
Starting Out With C++, Early Objects - With Access Package
8th Edition
ISBN: 9780133441840
Author: GADDIS
Publisher: PEARSON
Question
Book Icon
Chapter 19, Problem 4PC
Program Plan Intro

Tree Height

Program Plan:

  • Define a class BTreeNode to create nodes for binary search tree items.
    • Include all the required header files.
    • Initialize a value to the node, and set the left child of node to leftp and right child of node to rightp .
  • Define a class to create a Binary Search Tree.
    • Create a function int height that returns height of the tree.
  • Create a function bool search to search a particular item in tree.
    • Create function void insert to insert nodes into the tree.
  • Create a function leafCount that counts no. of leaves present in a level.
    • Create a function void inorder to sort items in inorder traversal.
  • Declare the main function.
    • Prompt the user to enter 5 numbers to be inserted into tree.
  • Sort the items present in the tree in inorder traversal and return the height of the Binary Search Tree.

Blurred answer
Students have asked these similar questions
Binary search tree. Write a function named totalSum that takes as parameter the root of the binary search tree(with the following type) and returns the total sum of the numbers in the tree. struct tree{    int data;     struct tree *left, *right; };
1.) Design a Binary Search Tree ADT by using following functions. Include the function definitions & run the program (Kindly include header files as well). Paste the output as a screenshot and write the code in your answer sheet. insert(int val)find(int x)************************************************************************************ class btNode { public:             int info; btNode *lLink;              btNode *rLink;             btNode(int e, btNode *l = NULL, btNode *r = NULL)             {                         info = e;          lLink = l;                         rLink = r;             }             btNode()             {                         lLink = NULL;                         rLink = NULL;             } }; class binarySTADT { private:             btNode *root; int count = 0; public:              binarySTADT()             {                         root = NULL;             }             void insert(int val); // function to insert a given value in the tree.…
F# Exercise, BST write the following binary search tree functions in F# for a binary search tree of integers. Use the following type definition for a BST (copy this into your solution):  F# system functions (such as min) and the method in the List module such as List.map. are not allowed // Tree definition for problem: type BST =        | Empty        | TreeNode of int * BST * BST insert value tree: Inserts the value into the tree and returns the resulting tree. The resulting tree does NOT need to be balanced. If the value already exists in the tree, return the tree without inserting the value. search value tree: Returns true if the value is in the tree and false otherwise. count func tree: The parameter func is a Boolean function that takes a single parameter and returns true or false. The function tests the value of each node with func and returns the number of nodes that evaluate to true. evenCount tree: Returns the number of nodes that contain even integers. REQUIREMENT: This…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education