REVEL for Gaddis C++ -- Access Card (What's New in Computer Science)
REVEL for Gaddis C++ -- Access Card (What's New in Computer Science)
1st Edition
ISBN: 9780134403922
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
C++ Data Structures (Binary Trees)- Write the definition of the function nodeCount that returns the number of nodes in the binary tree. Add this function to the class binaryTreeType and create a program to test this function. Here are the headers: binaryTree.h //Header File Binary Search Tree #ifndef H_binaryTree #define H_binaryTree #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; };    //Definition of the class template <class elemType> class binaryTreeType { public: const binaryTreeType<elemType>& operator= (const binaryTreeType<elemType>&); //Overload the assignment operator. bool isEmpty() const; //Function to determine whether the binary tree is empty. //Postcondition: Returns true if the binary tree is empty; // otherwise, returns false. void inorderTraversal() const; //Function to do an inorder…
In this chapter, the class to implement the nodes of a linked list is defined as a struct. The following rewrites the definition of the struct nodeType so that it is declared as a class and the member variables are private. template <class Type>class nodeType{public:const nodeType<Type>& operator=(const nodeType<Type>&);//Overload the assignment operator.void setInfo(const Type& elem);//Function to set the info of the node.//Postcondition: info = elem;Type getInfo() const;//Function to return the info of the node.//Postcondition: The value of info is returned.void setLink(nodeType<Type> *ptr);//Function to set the link of the node.//Postcondition: link = ptr;nodeType<Type>* getLink() const;//Function to return the link of the node.//Postcondition: The value of link is returned.nodeType();//Default constructor//Postcondition: link = NULL;nodeType(const Type& elem, nodeType<Type> *ptr);//Constructor with parameters//Sets info point to…
In this chapter, the class to implement the nodes of a linked list is defined as a struct . The following rewrites the definition of the struct nodeType so that it is declared as a class and the member variables are private. template <class Type> class nodeType{ public:     const nodeType<Type>& operator=(const nodeType<Type>&);        //Overload the assignment operator.     void setInfo(const Type& elem);      //Function to set the info of the node.      //Postcondition: info = elem;     Type getInfo() const;      //Function to return the info of the node.      //Postcondition: The value of info is returned.     void setLink(nodeType<Type> *ptr);      //Function to set the link of the node.      //Postcondition: link = ptr;     nodeType<Type>* getLink() const;      //Function to return the link of the node.      //Postcondition: The value of link is returned.     nodeType();       //Default constructor       //Postcondition: link = nullptr;…
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