EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134379371
Author: MUGANDA
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
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
In C++, develop an algorithm that inserts the value val into a binary search tree with root.  If the tree is empty, root = null. The algorithm returns the root of the tree containing the added item. You should assume that “new node” creates a new node with data field data and reference fields left (for left child) and right (for right child).
Create a binary linked tree, and traverse the tree by using the recursive function. The structure of the tree is as follow: //PICTURE//   You should input the nodes in pre-order sequence. If a child of a node is NULL, input a space. Write the function of create binary tree, pre-order to print the nodes, in-order to print the nodes and post-order to print the nodes. Count the height of the tree.
Create a binary linked tree, and traverse the tree by using the recursive function. The structure of the tree is as follows: //check pic//  You should input the nodes in pre-order sequence. If a child of a node is NULL, input a space. Write the function of create binary tree, pre-order to print the nodes, in-order to print the nodes and post-order to print the nodes. Count the height of the tree.   Hints: Header file typedef char ElemType;   typedef struct node//define the type of binary tree node {                                       }BTnode;       Source file #include <stdio.h> #include <stdlib.h> #include "tree.h"   BTnode * createTree()//create the binary tree,return the root {             BTnode *tnode;// tnode is the root             char elem;                                ;//input the character                            //if the input is a space,set the pointer as NULL               Else// if the input is not a space,generate the binary node and create its left…
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