Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 19, Problem 7PC
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 destructor BST & BST::operator=(BST &t)for assignment operator.
- Create a function void BST::destroyTree that deallocates all storage for nodes of a tree using the destructor.
- 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.
- Print the items present in the new tree by reassigning the values of the old tree.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Complete the Binary Search Tree class using C++ program:
1. Implement member function for deleteNode
2. Implement member functions for Pre-order and Post-order traversal
3. Develop the menu for different tasks as shown in sample output.
Sample Output: -
Complete the Binary Search Tree class:
1. Implement member function for deleteNode
2. Implement member functions for Pre-order and Post-order traversal
3. Develop the menu for different tasks as shown in sample output.
Sample Output: -
F# Exercise, BST
write the following binary search tree functions in F# for a binary search tree of integers. Use the following type definition for a BST (copy this into your solution):
F# system functions (such as min) and the method in the List module such as List.map. are not allowed
// Tree definition for problem:
type BST =
| Empty
| TreeNode of int * BST * BST
insert value tree: Inserts the value into the tree and returns the resulting tree. The resulting tree does NOT need to be balanced. If the value already exists in the tree, return the tree without inserting the value.
search value tree: Returns true if the value is in the tree and false otherwise.
count func tree: The parameter func is a Boolean function that takes a single parameter and returns true or false. The function tests the value of each node with func and returns the number of nodes that evaluate to true.
evenCount tree: Returns the number of nodes that contain even integers. REQUIREMENT: This…
Chapter 19 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.1 - Prob. 19.3CPCh. 19.1 - Prob. 19.4CPCh. 19.1 - Prob. 19.5CPCh. 19.1 - Prob. 19.6CPCh. 19.2 - Prob. 19.7CPCh. 19.2 - Prob. 19.8CPCh. 19.2 - Prob. 19.9CPCh. 19.2 - Prob. 19.10CP
Ch. 19.2 - Prob. 19.11CPCh. 19.2 - Prob. 19.12CPCh. 19 - Prob. 1RQECh. 19 - Prob. 2RQECh. 19 - Prob. 3RQECh. 19 - Prob. 4RQECh. 19 - Prob. 5RQECh. 19 - Prob. 6RQECh. 19 - Prob. 7RQECh. 19 - Prob. 8RQECh. 19 - Prob. 9RQECh. 19 - Prob. 10RQECh. 19 - Prob. 11RQECh. 19 - Prob. 12RQECh. 19 - Prob. 13RQECh. 19 - Prob. 14RQECh. 19 - Prob. 15RQECh. 19 - Prob. 16RQECh. 19 - Prob. 17RQECh. 19 - Prob. 18RQECh. 19 - Prob. 19RQECh. 19 - Prob. 20RQECh. 19 - Prob. 1PCCh. 19 - Prob. 2PCCh. 19 - Prob. 3PCCh. 19 - Prob. 4PCCh. 19 - Prob. 5PCCh. 19 - Prob. 6PCCh. 19 - Prob. 7PCCh. 19 - Prob. 8PCCh. 19 - Prob. 9PCCh. 19 - Prob. 10PC
Knowledge Booster
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
- Computer Science QUESTION: Expression tree is an application of binary tree to represent arithmetic expression. Write a program to implement an ExpressionTree class that can represent an arithmetic expression with binary operators and integer operands including floating-point. Limit the operators to addition, subtraction, multiplication and division. Operands can be constants or variables. Your class should be able to build a tree from its signature, and evaluate it on a set of values for the variable operands.arrow_forwardPythin: A binary search tree, write a function that finds and returns the median value. Assume that the class member variable. [_size] contains the number of elements in the binary search tree. What is the time complexity of your function? def find_median(self):arrow_forwardText concordance using BST 1 Project description Write a cross-reference program that constructs a binary search tree (any type, including splay tree) with all words included from a text file and records the positions (word or line numbers) on which these words were used. These line numbers should be stored on linked lists associated with the nodes of the tree. After the input file has been processed, print in alphabetical order all words of the text file along with the corresponding list of numbers of the lines in which the words occur. 2 What to turn in You will turn in a short written report containing: A description of the significant choices/issues in the design of your code. The source-code of your program. 3 Coding standards A percentage of your grade will be based on the quality of your code, so pay attention to it. Discuss changes (if any) you made to programs presented in class. Take extra care in documenting the code you are implementing on your…arrow_forward
- keep track of currnt node of AVl tree write a function that returns the current node and its value in an AVL tree with 0(1) complexityarrow_forward1. Modify the implementation of binary search tree and add a function to count the number of leaf nodes. 2. Modify the implementation of binary search tree and add a function to calculate the height of the tree. Run this project in C++.arrow_forwardIn JAVA code Write an algorithm for deleting a node of a Binary Search Tree. Take note that the Binary Search Tree property must be satisfied after a node is removed from a Binary Search Tree.arrow_forward
- (binary search tree c++)i am having issues with my code i am able to insert names into into the tree but they do not save(it says tree is empty). i will show you a picture of my output(black background) and a picture of the desired output(white background), i will also include my source main and .h class. //bt.cpp - file contains member functions#include "bt.h"#include <iostream>using namespace std;//ConstructorBT::BT(){ root = NULL;} //Insert new item in BSTvoid BT::insert(string d){ node* t = new node; node* parent; t->data = d; t->left = NULL; t->right = NULL; parent = NULL; if (isEmpty()) root = t; else { //Note: ALL insertions are as leaf nodes node* curr; curr = root; // Find the Node's parent while (curr) { parent = curr; if (t->data > curr->data) curr = curr->right; else curr = curr->left; }…arrow_forwardProgramming questions:typedef struct node { int data; struct node *left, *right;}BT;The node structure of the binary tree (BT) is shown above. There is a binary tree T, please complete the function: int degreeone(BT *T) to compute how many degree 1 node in the BT. The T is the root pointer, and the function shoule return the total number of degree 1 node.arrow_forwardProgramming 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 Treearrow_forward
- When a tree is discarded on a computer system without trash collection, the programmer is responsible for reallocating all of the memory used by the tree's nodes. Create Deallocate(tree), an iterative algorithm that achieves this. How flexible is the arrangement of the code's lines?arrow_forwardCoding in c for binary tree file system which has inorder, postorder and preorder traversal.File system that has 4 levels.arrow_forwardQuestion 4 Write a Lisp functions for Binary Search Tree (of numbers). (define insertTree (x tree)) returns a new tree with x inserted. (define findInTree(x tree)) return true if x is in the tree. Full explain this question and text typing work onlyarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education