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
Function 1: draw_subregion Complete the implementation of draw_subregion. This function has the following parameters: my_turtle: A turtle object (which will do the drawing) polygon_points: A list of (x, y) points (i.e. a list of tuples) that defines the points of a polygon. This function should make the turtle draw the polygon given by the points. Make sure that you lift your pen before heading to the first point. You should also make sure you return to the very first point at the end (i.e. you will go to the first point in the list two times: once at the beginning, and once at the end). Language Python
#include <stdio.h>#include <stdlib.h>#include <time.h> struct treeNode {  struct treeNode *leftPtr;  int data;  struct treeNode *rightPtr;}; typedef struct treeNode TreeNode;typedef TreeNode *TreeNodePtr; void insertNode(TreeNodePtr *treePtr, int value);void inOrder(TreeNodePtr treePtr);void preOrder(TreeNodePtr treePtr);void postOrder(TreeNodePtr treePtr); int main(void) {  TreeNodePtr rootPtr = NULL;   srand(time(NULL));  puts("The numbers being placed in the tree are:");   for (unsigned int i = 1; i <= 10; ++i) {    int item = rand() % 15;    printf("%3d", item);    insertNode(&rootPtr, item);  }   puts("\n\nThe preOrder traversal is: ");  preOrder(rootPtr);   puts("\n\nThe inOrder traversal is: ");  inOrder(rootPtr);   puts("\n\nThe postOrder traversal is: ");  postOrder(rootPtr);} void insertNode(TreeNodePtr *treePtr, int value) {  if (*treePtr == NULL) {    *treePtr = malloc(sizeof(TreeNode));     if (*treePtr != NULL) {      (*treePtr)->data = value;…
#include <stdio.h>#include <stdlib.h>#include <time.h> struct treeNode {    struct treeNode* leftPtr;    int data;    struct treeNode* rightPtr;}; typedef struct treeNode TreeNode;typedef TreeNode* TreeNodePtr; void insertNode(TreeNodePtr* treePtr, int value);void inOrder(TreeNodePtr treePtr);void preOrder(TreeNodePtr treePtr);void postOrder(TreeNodePtr treePtr); int main(void) {    TreeNodePtr rootPtr = NULL;     srand(time(NULL));    puts("The numbers being placed in the tree are:");     for (unsigned int i = 1; i <= 10; ++i) {        int item = rand() % 15;        printf("%3d", item);        insertNode(&rootPtr, item);    }     puts("\n\nThe preOrder traversal is: ");    preOrder(rootPtr);     puts("\n\nThe inOrder traversal is: ");    inOrder(rootPtr);     puts("\n\nThe postOrder traversal is: ");    postOrder(rootPtr);} void insertNode(TreeNodePtr* treePtr, int value) {    if (*treePtr == NULL) {        *treePtr = malloc(sizeof(TreeNode));         if…
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