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

Concept explainers

Question
Book Icon
Chapter 20, 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
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…
A "generic" data structure cannot use a primitive type as its generic type. O True 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
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning