Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 21, Problem 4PC
Program Plan Intro

Height of the Binary Tree

Program Plan:

  • Create a template prefix and define the template class BinaryTree to perform the following functions:
    • Declare the required variables.
    • Declare the function prototypes.
    • Define the no-argument generic constructor BinaryTree() to initialize the root value as null.
    • Call the functions insertNode(), remove(), displayInOrder(), and treeHeight().
    • Define the generic function insert() to insert the node in position pointed by the tree node pointer in a tree.
    • Define the generic function insertNode() to create a new node and it should be passed inside the insert() function to insert a new node into the tree.
    • Define the generic function remove()which calls deleteNode() to delete the node.
    • Define the generic function deleteNode() which deletes the node stored in the variable num and it calls the makeDeletion() function to delete a particular node passed inside the argument.
    • Define the generic function makeDeletion()which takes the reference to a pointer to delete the node and the brances of the tree corresponding below the node are reattached.
    • Define the generic function displayInOrder()to display the values in the subtree pointed by the node pointer.
    • Define the generic function getTreeHeight() to count the height of the tree.
    • Define the generic function TreeHeight()which calls getTreeHeight() to display the height of the tree.
  • In main() function,
    • Create a tree with integer data type to hold the integer values.
    • Call the function treeHeight() to print the initial height of the tree.
    • Call the function insertNode() to insert the node in a tree.
    • Call the function displayInOrder() to display the nodes inserted in the  order.
    • Call the function remove() to remove the nodes from tree.
    • Call the function treeHeight() to print the height of the tree after deleting the nodes.

Blurred answer
Students have asked these similar questions
Concatenate Map This function will be given a single parameter known as the Map List. The Map List is a list of maps. Your job is to combine all the maps found in the map list into a single map and return it. There are two rules for addingvalues to the map. You must add key-value pairs to the map in the same order they are found in the Map List. If the key already exists, it cannot be overwritten. In other words, if two or more maps have the same key, the key to be added cannot be overwritten by the subsequent maps.   Signature:   public static HashMap<String, Integer> concatenateMap(ArrayList<HashMap<String, Integer>> mapList) Example: INPUT: [{b=55, t=20, f=26, n=87, o=93}, {s=95, f=9, n=11, o=71}, {f=89, n=82, o=29}]OUTPUT: {b=55, s=95, t=20, f=26, n=87, o=93} INPUT: [{v=2, f=80, z=43, k=90, n=43}, {d=41, f=98, y=39, n=83}, {d=12, v=61, y=44, n=30}]OUTPUT: {d=41, v=2, f=80, y=39, z=43, k=90, n=43} INPUT: [{p=79, b=10, g=28, h=21, z=62}, {p=5, g=87, h=38}, {p=29,…
Absolute Value TemplateWrite a function template that accepts an argument and returns its absolute value. The absolute value of a number is its value with no sign. For example, the absolute value of -5 is 5, and the absolute value of 2 is 2. Test the template in a simple driver program being sure to send the template short, int, double, float, and long data values.
// CONSTANT//   static const int MAX_SIZE = ____//     IntSet::MAX_SIZE is the highest # of elements an IntSet//     can accommodate.// CONSTRUCTOR//   IntSet()//     Pre:  (none)//     Post: The invoking IntSet is initialized to an empty//           IntSet (i.e., one containing no relevant elements).// CONSTANT MEMBER FUNCTIONS (ACCESSORS)//   int size() const//     Pre:  (none)//     Post: Number of elements in the invoking IntSet is returned.//   bool isEmpty() const//     Pre:  (none)//     Post: True is returned if the invoking IntSet has no relevant//           relevant elements, otherwise false is returned.//   bool contains(int anInt) const//     Pre:  (none)//     Post: true is returned if the invoking IntSet has anInt as an//           element, otherwise false is returned.//   bool isSubsetOf(const IntSet& otherIntSet) const//     Pre:  (none)//     Post: True is returned if all elements of the invoking IntSet//           are also elements of otherIntSet, otherwise false…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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