Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++: Early Objects (9th Edition)
9th Edition
ISBN: 9780134400242
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
Question
Book Icon
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.

Blurred answer
Students 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
Knowledge Booster
Background pattern image
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