STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 19, Problem 10PC
Program Plan Intro
Prefix Representation of Binary Trees
Program Plan:
“IntBinaryTree.h”:
- Include all the required header files.
- Define the class “TreeNode”.
- Assign a value to the node, and set the left child of node to leftp and right child of node to rightp.
- Create function void insert to insert items into nodes of tree.
- Create a function void destroySubtree that calls the binary tree function and deletes the nodes which are present in the tree.
- Function to overload the stream insertion and print tree elements void treePrint is called.
- Functions to display the tree in inorder , pre order and post order void displayInOrder , void displayPreOrder(TreeNode *) and void displayPostOrder are called.
- Print all the elements of the tree.
“IntBinaryTree.cpp”:
- Include all the required header files.
- Create a tree Function void IntBinaryTree::insert that inserts a number into a given sub tree of the main binary search tree by checking for availability of free nodes in the binary search tree.
- Create a function void IntBinaryTree::destroySubtree calls the binary tree function and deletes the nodes which are present in the tree.
- Create a function bool IntBinaryTree::search where user enters a number to search, the function search searches the number inside the binary search tree and if present returns true, else false otherwise .
- Create a tree function void IntBinaryTree::remove that deletes the node in the given tree that has same value as entered by user by searching the left and right subtrees.
- Display the tree elements in inorder, pre order and post order.
- Display the items present in tree prefix type.
“main.cpp”:
- Include all the required header files.
- Call the Binary tree class to build a tree.
- Enter elements into the tree.
- Delete elements and print the elements of the tree in prefix form.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
One can easily see the benefits of a binary search tree when comparing it to other data structures like a linked list or an array.
Write 5 functions in C++ for a binary search tree.
DeleteAll() deletes all the nodes in the binary tree recurively.
findNode(int item) //finds the node in the tree ITERATIVELY.
countNonLeaves() takes a binary tree and counts the number of nodes that are not leaves in the given Binary Tree.
OneChild() Calculate the number of nodes that have only one child in a given Binary Tree.
findRange() return the range value of a Binary Search Tree. [ max(BST), min(BST) ] where max is the maximum value of the BST and min is theminimum value of the given BST.
All of these functions should be called in the main and tested. Thank you.
C programming I need help writing a code that uses a struct pointer into a binary tree and using the same pointer into an array
Chapter 19 Solutions
STARTING OUT WITH C++ MPL
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
Similar questions
- The benefits of a binary search tree over other data structures, such as a linked list or an array, are obvious.arrow_forwardCreate a Binary Search Tree Class using C++ with the following Operations: Operations: Insert(int n) : Add a node the tree with value n. Its O(lgn) Find(int n) : Find a node the tree with value n. Its O(lgn) Delete (int n) : Delete a node the tree with value n. Its O(lgn) Display(): Prints the entire tree in increasing order. O(n).arrow_forwardThe benefits of a binary search tree are evident when compared to other data structures like a linked list or an array.arrow_forward
- Python binary search tree: a function that takes in a root, p, and checks whether the tree rooted in p is a binary search tree or not. What is the time complexity of your function? def is_bst(self, p: Node):arrow_forwardWhat are the benefits of employing a binary search tree?arrow_forwardin c++, write a function to find the height of a specific node in a Binary Search Tree.arrow_forward
- The advantages of a binary search tree are clearly evident when compared to those of other data structures, such as a linked list or an array.arrow_forwardCreate a Binary Search Tree Class with the following four Operations using a single C++ program: Operations: 1. Insert(int n) : Add a node the tree with value n. Its O(lgn) 2. Find(int n) : Find a node the tree with value n. Its O(lgn) 3. Delete (int n) : Delete a node the tree with value n. Its O(lgn) 4. Display(): Prints the entire tree in increasing order. O(n).arrow_forwardIn C++arrow_forward
- JavaScript: Search the Tree A binary search tree is a data structure that consists of JavaScript objects called "nodes". A tree always has a root node which holds its own integer valueproperty and can have up to two child nodes (or leaf nodes), a left and right attribute. A leaf node holds a value attribute and, likewise, a left and rightattribute each potentially pointing to another node in the binary tree. Think of it as a Javascript object with potentially more sub-objects referenced by the left and right attributes (as seen in assignment 4). There are certain rules that apply to a binary tree: A node's left leaf node has a value that is <= than to its own value A node's right leaf node has a value that is => its own value In other words: let node = {value: <some number>left: <a node object with value attribute <= this object's value>right: <a node object with value attribute >= this object's value>} If you need a visual aid, below is an example of…arrow_forwardProgram 3: Binary Search Tree Program Objective The primary objective of this program is to learn to implement binary search trees and to combine their functionalities with linked lists. Program Description In a multiplayer game, players' avatars are placed in a large game scene, and each avatar has its information in the game. Write a program to manage players' information in a multiplayer game using a Binary Search (BS) tree for a multiplayer game. A node in the BS tree represents each player. Each player should have an ID number, avatar name, and stamina level. The players will be arranged in the BS tree based on their ID numbers. If there is only one player in the game scene, it is represented by one node (root) in the tree. Once another player enters the game scene, a new node will be created and inserted in the BS tree based on the player ID number. Players during the gameplay will receive hits that reduce their stamina. If the players lose all their stamina, they vanish from the…arrow_forwardWhat is the advantage of a binary search tree over a binary tree?arrow_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