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 5PC
Program Plan Intro

Width 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(),displayInOrder(), and treeHeight()and getWidth().
    • Define the generic function insert() to insert the node in pointed by the tree node pointer in a tree.
    • Define the generic function insertNode() to create a new node and it is passed inside the insert() function to insert a new node into the tree.
    • .
    • 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.
    • Define the generic function numAtLevel() to calculate the number of levels until the desired level is reached.
    • Define the generic function getWidth() which calls the numAtLevel() function to count the width of the tree.
  • In main() function,
    • Create a tree with integer data type to hold the integer values.
    • Declare the array testvalues[] and initialize it with the values.
    • Use for loop to insert the values of testvalues[] array inside the binary tree using insertNode().
    • Call the function displayInOrder() to display the nodes inserted in the order.
    • Call the function treeHeight() to print the height of the tree after insertion.
    • Call the function getWidth() to print the width of the tree after insertion.
    • Display the height and width of the tree.

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,…
struct remove_from_front_of_dll { // Function takes no parameters, removes the book at the front of a doubly // linked list, and returns nothing. void operator()(const Book& unused) { //// TO-DO (13) |||| // Write the lines of code to remove the book at the front of "my_dll", // // Remember, attempting to remove an element from an empty data structure is // a logic error. Include code to avoid that. ///// END-TO-DO (13) //// } std::list& my_dll; };
Course: Data Structure and Algorithims Language: Java Kindly make the program in 2 hours. Task is well explained.  You have to make the proogram properly in Java: Restriction: Prototype cannot be change you have to make program by using given prototype. TAsk: Create a class Node having two data members int data;     Node next;   Write the parametrized constructor of the class Node which contain one parameter int value assign this value to data and assign next to null Create class LinkList having one data members of type Node. Node head Write the following function in the LinkList class publicvoidinsertAtLast(int data);//this function add node at the end of the list publicvoid insertAthead(int data);//this function add node at the head of the list publicvoid deleteNode(int key);//this function find a node containing "key" and delete it publicvoid printLinkList();//this function print all the values in the Linklist public LinkListmergeList(LinkList l1,LinkList l2);// this function…
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