EBK STARTING OUT WITH C++ FROM CONTROL
EBK STARTING OUT WITH C++ FROM CONTROL
9th Edition
ISBN: 8220106714379
Author: 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
#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…
#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;…
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