STARTING OUT C++,+MATLAB+MYPROGRAMLAB>C
STARTING OUT C++,+MATLAB+MYPROGRAMLAB>C
19th Edition
ISBN: 9781323948637
Author: GADDIS
Publisher: PEARSON C
bartleby

Concept explainers

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

Copy the binary tree

Program Plan:

  • Declare the header file section.
  • Create a template prefix and define the template class IntBinaryTree to perform the following functions:
    • Declare the required variables.
    • Declare the function prototypes.
    • Define the no-argument generic constructor IntBinaryTree () to initialize the root value as null.
    • Define destructor for IntBinaryTree () class and call the function destroySubTree() to destroy the sub tree.
    • Call the functions insertNode(),displayInOrder(), and remove().
    • Declare the overloaded assignment operator for binary tree.
    • Define the generic function insert () to insert the node in pointed by the tree node pointer in a tree.
    • Define the generic copy constructor for IntBinaryTree class to copy the binary tree using copyTree() function.
    • Define the generic function insert () to insert the node in pointed by the tree node pointer in a tree.
    • Define the generic function insertNode() to create a new node and it is passed inside the insert() function to insert a new node into the tree.
    • Define the generic function destroySubTree() to delete the left and right subtree.
    • Define the generic function remove()which calls deleteNode() to delete the node.
    • Define the generic function deleteNode()which delete the node stored in the variable num and it calls the makeDeletion() function to delete a particular node passed inside the argument.
    • Define the generic function makeDeletion()which takes the reference to a pointer to delete the node and the brances of the tree corresponding below the node are reattached.
    • Define the generic function displayInOrder()to display the values in the subtree pointed by the node pointer.
    • Define the generic function copyTree()to copy the entire binary tree.
  • In main() function,
    • Create two binary trees with integer data type to hold the integer values.
    • Call the function insertNode() to insert some nodes into tree.
    • Using assignment operator assign one tree into another tree using respective variables.
    • Call the function displayInOrder() to display the nodes in order for tree1 and tree 2.
    • Create another object for IntBinaryTree class  and copy the tree1 to tree3 using copy constructor and display the tree using displayInOrder() function.

Blurred answer
Students have asked these similar questions
please help on how to write this code   here is "BinaryNode.java" // BinaryNode class; stores a node in a tree. // // CONSTRUCTION: with (a) no parameters, or (b) an Object, // or (c) an Object, left child, and right child. // // *******************PUBLIC OPERATIONS********************** // int size( ) --> Return size of subtree at node // int height( ) --> Return height of subtree at node // void printPostOrder( ) --> Print a postorder tree traversal // void printInOrder( ) --> Print an inorder tree traversal // void printPreOrder( ) --> Print a preorder tree traversal // BinaryNode duplicate( )--> Return a duplicate tree /** * Binary node class with recursive routines to * compute size and height. */ class BinaryNode { public BinaryNode( ) { this( 0, null, null ); } public BinaryNode( int theElement, BinaryNode lt, BinaryNode rt ) { element = theElement; left = lt; right = rt; } /** * Return the size of the binary tree rooted at t. */ public static int size(…
only c here is "BinaryNode.java" // BinaryNode class; stores a node in a tree. // // CONSTRUCTION: with (a) no parameters, or (b) an Object, // or (c) an Object, left child, and right child. // // *******************PUBLIC OPERATIONS********************** // int size( ) --> Return size of subtree at node // int height( ) --> Return height of subtree at node // void printPostOrder( ) --> Print a postorder tree traversal // void printInOrder( ) --> Print an inorder tree traversal // void printPreOrder( ) --> Print a preorder tree traversal // BinaryNode duplicate( )--> Return a duplicate tree /** * Binary node class with recursive routines to * compute size and height. */ class BinaryNode { public BinaryNode( ) { this( 0, null, null ); } public BinaryNode( int theElement, BinaryNode lt, BinaryNode rt ) { element = theElement; left = lt; right = rt; } /** * Return the size of the binary tree rooted at t. */ public static int size( BinaryNode t ) { if( t == null ) return…
Build a tree identification code. please Fast  thank you
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