STARTING OUT WITH C++ MPL
STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 19, Problem 5PC
Program Plan Intro

Tree Width

Program Plan:

  • Define a class BTreeNode to create nodes for binary search tree items.
    • Include all the required header files.
    • Initialize a value to the node, and set the left child of node to leftp and right child of node to rightp .
  • Define a class to create a Binary Search Tree.
    • Create a function int width that returns width of the tree.
  • Create a function bool search to search a particular item in tree.
    • Create a function leafCounter that counts no. of leaves present in a level.
  • Create function void insert to insert nodes into the tree.
    • Create a function void inorder to sort items in inorder traversal.
  • Declare the main function.
    • Prompt the user to enter 5 numbers to be inserted into tree.
  • Sort the items present in the tree in inorder traversal and return the width of the Binary Search Tree.

Blurred answer
Students have asked these similar questions
Language/Type: C++ binary trees pointers recursion Write a function named hasPath that interacts with a tree of BinaryTreeNode structures representing an unordered binary tree. The function accepts three parameters: a pointer to the root of the tree, and two integers start and end, and returns true if a path can be found in the tree from start down to end. In other words, both start and end must be element data values that are found in the tree, and end must be below start, in one of start's subtrees; otherwise the function returns false. If start and end are the same, you are simply checking whether a single node exists in the tree with that data value. If the tree is empty, your function should return false. For example, suppose a BinaryTreeNode pointer named tree points to the root of a tree storing the following elements. The table below shows the results of several various calls to your function: 67 88 52 1 21 16 99 45 Call Result Reason hasPath(tree, 67, 99) true path exists…
Tree Traversal Coding: How do I code the following in C program?  // ====== BEGIN INSERT FUNCTION DEFS TO WALK TREE ========= // define 3 functions - preorder, inorder, postorder to walk tree, printing out data (char) // associated with each node visited: void preorder (node* np) {} void inorder (node* np) {} void postorder (node* np) {}   walk.c file with the rest of the code given. #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <string.h>   #define MAX_STRING 200   // ========================== NODE/TREE DEFINITIONS ========================== // define node structure  typedef struct nd {   int data;   struct nd* left;   struct nd* right; } node;   // "new" function to create a node, set data value to d and children to NULL node* newNode(int d) {   node* np;   np = (node*)malloc(sizeof(node));   if (np != NULL) {     np->data = d;     np->left = NULL;     np->right = NULL;   }   return(np); }   // declare root of our binary tree…
C++ PROGRAMMINGBinary Search Trees SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS It doesn't have to be long, as long as you explain what the important parts of the code do. (The code is already implemented and correct, only the explanation needed)    #include "node.h" #include <iostream> using namespace std; class BSTree {     node* root;     int size;     node* create_node(int num, node* parent) {         node* n = (node*) malloc( sizeof(node) );         n->element = num;         n->parent = parent;         n->right = NULL;         n->left = NULL;         return n;     }     bool search(node* curr, int num) {         if (curr == NULL) {             return false;         }         if (num == curr->element) {             return true;         }         if (num < curr->element) {             return search(curr->left, num);         }         return search(curr->right, num);     }     node* search_node(node* curr, int num) {         if (num ==…
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