Starting Out With C++: Early Objects (10th Edition)
Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

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

Tree Copy Constructor

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 copy constructor BST::BST(BST &t)that copies all the items present in the 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 print the items.
    • Copy all the items of the tree elements.
  • Prompt the user to enter a new value to be entered into tree.
    • Print the items present in new tree in order traversal.
  • Print the items present in original tree using copy constructor.

Blurred answer
Students have asked these similar questions
Binary Search Tree Empirical and Theoretical ResultsPart 1: we need to define a binary search tree data structure. Also, we need to implement the following functions:1. Insert Sorted: BSTREE insert(BSTREE root, int num): root points to a node in a binary search tree; num is a number to be inserted in the tree rooted at “root”. This function returns the root of the modified tree.2. Print Elements: void inorder traversal(BSTREE root, FILE *fp): root points to a node in a binary search tree. This function does not return anything, but prints out, to the file specified, the nodes in the tree rooted at “root” by performing an inorder traversal. Part 2: Test the performance of the designed data structure using theoretical and experimental approaches as follows:1. Dataset 1-Dataset is sorted- Add code to insert the numbers 1...n in that order in an initially empty doubly linked list and a binary search tree.a. Run it on different values of n where :i. n = 20,000ii. n = 50,000iii. n =…
struct insert_into_bst { // Function takes a constant Book as a parameter, inserts that book indexed by // the book's ISBN into a binary search tree, and returns nothing. void operator()(const Book& book) { // // TO-DO (7) ||| ///// // Write the lines of code to insert the key (book's ISBN) and value // ("book") pair into "my_bst". END-TO-DO (7) | } std::map& my_bst; };
Programming Language: C Programming 1. Make a code of implementation of the Binary Tree program and explain each line on how it works NOTE: it's Binary Tree , NOT Binary Search Tree
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