SlideShare a Scribd company logo
Please i need help on following program using C++ Language.
Add these three functions to the class binaryTreeType (provided) at below.
Write the definition of the function, nodeCount, that returns the number of nodes in the binary
tree.
Write the definition of the function, leavesCount, that takes as a parameter a pointer to the root
node of a binary tree and returns the number of leaves in a binary tree.
Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Print
the original tree and the resulting tree using a pre-order traversal.
Write a program to test your new functions. Use the data provided to build your binary search
tree (-999 is the sentinel):
Data: 65 55 22 44 61 19 90 10 78 52 -999
HERE IS BinaryTreeType.h
Solution
#ifndef H_binaryTree
#define H_binaryTree
#include <iostream>
using namespace std;
//Definition of the Node
template <class elemType>
struct nodeType
;
//Definition of the category
template <class elemType>
class binaryTreeType
to work out whether or not the binary tree is empty.
//Postcondition: Returns true if the binary tree is empty;
// otherwise, returns false.
void inorderTraversal() const;
//Function associated do} an inorder traversal of the binary tree.
//Postcondition: Nodes square measure written in inorder sequence.
void preorderTraversal() const;
//Function to try to to a preorder traversal of the binary tree.
//Postcondition: Nodes square measure written in preorder sequence.
void postorderTraversal() const;
//Function to try to to a postorder traversal of the binary tree.
//Postcondition: Nodes square measure written in postorder sequence.
int treeHeight() const;
//Function to see the peak of a binary tree.
//Postcondition: Returns the peak of the binary tree.
void destroyTree();
//Function to destroy the binary tree.
//Postcondition: Memory area occupied by every node
// is deallocated.
// root = NULL;
virtual bool search(const elemType& searchItem) const = 0;
//Function to see if searchItem is within the binary
//tree.
//Postcondition: Returns true if searchItem is found in
// the binary tree; otherwise, returns
// false.
virtual void insert(const elemType& insertItem) = 0;
//Function to insert insertItem within the binary tree.
//Postcondition: If there's no node within the binary tree
// that has identical information as insertItem, a
// node with the information insertItem is made
// and inserted within the binary search tree.
virtual void deleteNode(const elemType& deleteItem) = 0;
//Function to delete deleteItem from the binary tree
//Postcondition: If a node with identical information as
// deleteItem is found, it's deleted from
// the binary tree.
// If the binary tree is empty or
// deleteItem isn't within the binary tree,
// Associate in Nursing applicable message is written.
binaryTreeType(const binaryTreeType<elemType>& otherTree);
//Copy creator
binaryTreeType();
//Default creator
~binaryTreeType();
//Destructor
protected:
nodeType<elemType> *root;
private:
void copyTree(nodeType<elemType>* &copiedTreeRoot,
nodeType<elemType>* otherTreeRoot);
//Makes a replica of the binary tree to that
//otherTreeRoot points.
//Postcondition: The pointer copiedTreeRoot points to
// the basis of the derived binary tree.
void destroy(nodeType<elemType>* &p);
//Function to destroy the binary tree to that p points.
//Postcondition: Memory area occupied by every node, in
// the binary tree to that p points, is
// deallocated.
// p = NULL;
void inorder(nodeType<elemType> *p) const;
//Function associated do} an inorder traversal of the binary
//tree to that p points.
//Postcondition: Nodes of the binary tree, to which p
// points, square measure written in inorder sequence.
void preorder(nodeType<elemType> *p) const;
//Function to try to to a preorder traversal of the binary
//tree to that p points.
//Postcondition: Nodes of the binary tree, to which p
// points, square measure written in preorder
// sequence.
void postorder(nodeType<elemType> *p) const;
//Function to try to to a postorder traversal of the binary
//tree to that p points.
//Postcondition: Nodes of the binary tree, to which p
// points, square measure written in postorder
// sequence.
int height(nodeType<elemType> *p) const;
//Function to see the peak of the binary tree
//to that p points.
//Postcondition: Height of the binary tree to that
// p points is came back.
int max(int x, int y) const;
//Function to see the larger of x and y.
//Postcondition: Returns the larger of x and y.
};
//Definition of member functions
template <class elemType>
binaryTreeType<elemType>::binaryTreeType()
template <class elemType>
bool binaryTreeType<elemType>::isEmpty() const
come (root == NULL);
}
template <class elemType>
void binaryTreeType<elemType>::inorderTraversal() const
template <class elemType>
void binaryTreeType<elemType>::preorderTraversal() const
template <class elemType>
void binaryTreeType<elemType>::postorderTraversal() const
template <class elemType>
int binaryTreeType<elemType>::treeHeight() const
come height(root);
}
template <class elemType>
int binaryTreeType<elemType>::treeNodeCount() const
come nodeCount(root);
}
template <class elemType>
int binaryTreeType<elemType>::treeLeavesCount() const
come leavesCount(root);
}
template <class elemType>
void binaryTreeType<elemType>::copyTree
(nodeType<elemType>* &copiedTreeRoot,
nodeType<elemType>* otherTreeRoot)
} //end copyTree
template <class elemType>
void binaryTreeType<elemType>::inorder
(nodeType<elemType> *p) const

More Related Content

PDF
Add these three functions to the class binaryTreeType (provided).W.pdf
DOCX
Write a program in Java to implement the ADT Binary Tree part of who.docx
PDF
Please write in C++ and should be able to compile and debug.Thank yo.pdf
PDF
Tree Traversals A tree traversal is the process of visiting.pdf
PDF
Create an implementation of a binary tree using the recursive appr.pdf
DOCX
Once you have all the structures working as intended- it is time to co.docx
PPT
FRbsbsvvsvsvbshgsgsvzvsvvsvsvsvsvsvvev.ppt
PDF
In c++ format, for each function in the code, please using the comme.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
Write a program in Java to implement the ADT Binary Tree part of who.docx
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Tree Traversals A tree traversal is the process of visiting.pdf
Create an implementation of a binary tree using the recursive appr.pdf
Once you have all the structures working as intended- it is time to co.docx
FRbsbsvvsvsvbshgsgsvzvsvvsvsvsvsvsvvev.ppt
In c++ format, for each function in the code, please using the comme.pdf

Similar to Please i need help on following program using C++ Language.Add the.pdf (20)

PDF
C programming. Answer question only in C code Ninth Deletion with B.pdf
PDF
Binary Trees
PDF
Need Help with this Java Assignment. Program should be done in JAVA .pdf
PDF
Write the definitions of the member functions of the class nodeType..pdf
PDF
include ltiostreamgt include ltfstreamgt in.pdf
PDF
I have C++ question that I do not know how to do, Can you teach me t.pdf
DOCX
Running Head Discussion Board .docx
PDF
MAINCPP include ltiostreamgt include ltstringgt u.pdf
PDF
Write a C++ program that implements a binary search tree (BST) to man.pdf
DOCX
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
PDF
C++ BinaryTree Help Creating main function for Trees...Here are .pdf
DOCX
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
PDF
Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf
PDF
Templated Binary Tree implementing function help I need to im.pdf
PDF
Binary trees
DOCX
DS UNIT5_BINARY TREES.docx
DOCX
For this project, write a program that stores integers in a binary.docx
DOCX
Required to augment the authors Binary Search Tree (BST) code to .docx
DOCX
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
PDF
Given a newly created Binary Search Tree with the following numerica.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdf
Binary Trees
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Write the definitions of the member functions of the class nodeType..pdf
include ltiostreamgt include ltfstreamgt in.pdf
I have C++ question that I do not know how to do, Can you teach me t.pdf
Running Head Discussion Board .docx
MAINCPP include ltiostreamgt include ltstringgt u.pdf
Write a C++ program that implements a binary search tree (BST) to man.pdf
Assg 12 Binary Search TreesCOSC 2336 Spring 2019April.docx
C++ BinaryTree Help Creating main function for Trees...Here are .pdf
Assg 12 Binary Search Trees COSC 2336assg-12.cppAssg 12 Binary .docx
Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf
Templated Binary Tree implementing function help I need to im.pdf
Binary trees
DS UNIT5_BINARY TREES.docx
For this project, write a program that stores integers in a binary.docx
Required to augment the authors Binary Search Tree (BST) code to .docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Given a newly created Binary Search Tree with the following numerica.pdf
Ad

More from ezzi552 (20)

PDF
Execute the following code and identify the errors in the program. D.pdf
PDF
Essay question The genomes of lots and lots of organisms (mostly ba.pdf
PDF
Consider the language L = { anb2n n 0 }.Give an implementation.pdf
PDF
Case Study.You are the Chair of the Department of Surgery at a lar.pdf
PDF
An Unsorted Type ADT is to be extended by the addition of function S.pdf
PDF
alue 0.83 points M7-6 Calculating Cost of Goods Available for Sale, E.pdf
PDF
1)Using general mass-media (such as news sites) identify a recent co.pdf
PDF
1. The notion that two network exist in the brain, one for emotional.pdf
PDF
Which of the following is a bank liabilityA. Reserve deposits at .pdf
PDF
What was Eisenhower’s reinsurance plan What was Eisenhower’s r.pdf
PDF
What does the following program do What’s its time complexity Just.pdf
PDF
What is not true about the membranes of prokaryotic organism a. The.pdf
PDF
What behavior characteristics are associated with each of the four s.pdf
PDF
What are someways to better understand accounting There is a lot of.pdf
PDF
Based on the elements from the Ruby Payne readings create a resource.pdf
PDF
The answer has to be original.For this week’s discussion, complete.pdf
PDF
Assume you have a scanner object (called input).Declare an integer.pdf
PDF
6. Establishing priorities is an issue that local governments strugg.pdf
PDF
Suppose that A and B are attributes of a certain relational table. G.pdf
PDF
RHCE is least associated with which Rh group (D--, R1r, Ror, Rzy) .pdf
Execute the following code and identify the errors in the program. D.pdf
Essay question The genomes of lots and lots of organisms (mostly ba.pdf
Consider the language L = { anb2n n 0 }.Give an implementation.pdf
Case Study.You are the Chair of the Department of Surgery at a lar.pdf
An Unsorted Type ADT is to be extended by the addition of function S.pdf
alue 0.83 points M7-6 Calculating Cost of Goods Available for Sale, E.pdf
1)Using general mass-media (such as news sites) identify a recent co.pdf
1. The notion that two network exist in the brain, one for emotional.pdf
Which of the following is a bank liabilityA. Reserve deposits at .pdf
What was Eisenhower’s reinsurance plan What was Eisenhower’s r.pdf
What does the following program do What’s its time complexity Just.pdf
What is not true about the membranes of prokaryotic organism a. The.pdf
What behavior characteristics are associated with each of the four s.pdf
What are someways to better understand accounting There is a lot of.pdf
Based on the elements from the Ruby Payne readings create a resource.pdf
The answer has to be original.For this week’s discussion, complete.pdf
Assume you have a scanner object (called input).Declare an integer.pdf
6. Establishing priorities is an issue that local governments strugg.pdf
Suppose that A and B are attributes of a certain relational table. G.pdf
RHCE is least associated with which Rh group (D--, R1r, Ror, Rzy) .pdf
Ad

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Cell Structure & Organelles in detailed.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
master seminar digital applications in india
PDF
Classroom Observation Tools for Teachers
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Insiders guide to clinical Medicine.pdf
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Cell Structure & Organelles in detailed.
Abdominal Access Techniques with Prof. Dr. R K Mishra
O5-L3 Freight Transport Ops (International) V1.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPH.pptx obstetrics and gynecology in nursing
Supply Chain Operations Speaking Notes -ICLT Program
Anesthesia in Laparoscopic Surgery in India
master seminar digital applications in india
Classroom Observation Tools for Teachers
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
TR - Agricultural Crops Production NC III.pdf
Pre independence Education in Inndia.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Please i need help on following program using C++ Language.Add the.pdf

  • 1. Please i need help on following program using C++ Language. Add these three functions to the class binaryTreeType (provided) at below. Write the definition of the function, nodeCount, that returns the number of nodes in the binary tree. Write the definition of the function, leavesCount, that takes as a parameter a pointer to the root node of a binary tree and returns the number of leaves in a binary tree. Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Print the original tree and the resulting tree using a pre-order traversal. Write a program to test your new functions. Use the data provided to build your binary search tree (-999 is the sentinel): Data: 65 55 22 44 61 19 90 10 78 52 -999 HERE IS BinaryTreeType.h Solution #ifndef H_binaryTree #define H_binaryTree #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType ; //Definition of the category template <class elemType> class binaryTreeType to work out whether or not the binary tree is empty. //Postcondition: Returns true if the binary tree is empty; // otherwise, returns false. void inorderTraversal() const; //Function associated do} an inorder traversal of the binary tree. //Postcondition: Nodes square measure written in inorder sequence. void preorderTraversal() const;
  • 2. //Function to try to to a preorder traversal of the binary tree. //Postcondition: Nodes square measure written in preorder sequence. void postorderTraversal() const; //Function to try to to a postorder traversal of the binary tree. //Postcondition: Nodes square measure written in postorder sequence. int treeHeight() const; //Function to see the peak of a binary tree. //Postcondition: Returns the peak of the binary tree. void destroyTree(); //Function to destroy the binary tree. //Postcondition: Memory area occupied by every node // is deallocated. // root = NULL; virtual bool search(const elemType& searchItem) const = 0; //Function to see if searchItem is within the binary //tree. //Postcondition: Returns true if searchItem is found in // the binary tree; otherwise, returns // false. virtual void insert(const elemType& insertItem) = 0; //Function to insert insertItem within the binary tree. //Postcondition: If there's no node within the binary tree // that has identical information as insertItem, a // node with the information insertItem is made // and inserted within the binary search tree. virtual void deleteNode(const elemType& deleteItem) = 0; //Function to delete deleteItem from the binary tree //Postcondition: If a node with identical information as // deleteItem is found, it's deleted from // the binary tree. // If the binary tree is empty or // deleteItem isn't within the binary tree, // Associate in Nursing applicable message is written. binaryTreeType(const binaryTreeType<elemType>& otherTree); //Copy creator
  • 3. binaryTreeType(); //Default creator ~binaryTreeType(); //Destructor protected: nodeType<elemType> *root; private: void copyTree(nodeType<elemType>* &copiedTreeRoot, nodeType<elemType>* otherTreeRoot); //Makes a replica of the binary tree to that //otherTreeRoot points. //Postcondition: The pointer copiedTreeRoot points to // the basis of the derived binary tree. void destroy(nodeType<elemType>* &p); //Function to destroy the binary tree to that p points. //Postcondition: Memory area occupied by every node, in // the binary tree to that p points, is // deallocated. // p = NULL; void inorder(nodeType<elemType> *p) const; //Function associated do} an inorder traversal of the binary //tree to that p points. //Postcondition: Nodes of the binary tree, to which p // points, square measure written in inorder sequence. void preorder(nodeType<elemType> *p) const; //Function to try to to a preorder traversal of the binary //tree to that p points. //Postcondition: Nodes of the binary tree, to which p // points, square measure written in preorder // sequence. void postorder(nodeType<elemType> *p) const; //Function to try to to a postorder traversal of the binary //tree to that p points. //Postcondition: Nodes of the binary tree, to which p // points, square measure written in postorder // sequence.
  • 4. int height(nodeType<elemType> *p) const; //Function to see the peak of the binary tree //to that p points. //Postcondition: Height of the binary tree to that // p points is came back. int max(int x, int y) const; //Function to see the larger of x and y. //Postcondition: Returns the larger of x and y. }; //Definition of member functions template <class elemType> binaryTreeType<elemType>::binaryTreeType() template <class elemType> bool binaryTreeType<elemType>::isEmpty() const come (root == NULL); } template <class elemType> void binaryTreeType<elemType>::inorderTraversal() const template <class elemType> void binaryTreeType<elemType>::preorderTraversal() const template <class elemType> void binaryTreeType<elemType>::postorderTraversal() const template <class elemType> int binaryTreeType<elemType>::treeHeight() const come height(root); } template <class elemType> int binaryTreeType<elemType>::treeNodeCount() const come nodeCount(root); } template <class elemType> int binaryTreeType<elemType>::treeLeavesCount() const
  • 5. come leavesCount(root); } template <class elemType> void binaryTreeType<elemType>::copyTree (nodeType<elemType>* &copiedTreeRoot, nodeType<elemType>* otherTreeRoot) } //end copyTree template <class elemType> void binaryTreeType<elemType>::inorder (nodeType<elemType> *p) const