Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Header File Binary Search Tree #ifndef H _ binaryTree #define H _ binaryTree #include # IMPORTANT NOTICE # This is the header file
Header File Binary Search Tree
#ifndef HbinaryTree
#define HbinaryTree
#include
# IMPORTANT NOTICE
# This is the header file binaryTreeType class, which is handled in your lab session.
# For the Q of labexam, just scroll down all the way to the bottom
# and fill in the given function blocks.
#
using namespace std;
Definition of the Node
template
struct nodeType
elemType info;
nodeType lLink;
nodeType rLink;
;
Definition of the class
template
class binaryTreeType
public:
const binaryTreeType& operatorconst binaryTreeType&;
bool isEmpty const;
void inorderTraversal const;
void preorderTraversal const;
void postorderTraversal const;
int treeHeight const;
int treeNodeCount const;
For Questions:
int treeLeavesCount const;
void treeSwapSubtrees;
void treeSwapSubtreesOfNode;
int treeSingleParent const;
int treeSingleP const;
int treeLargest const;
int compareSubtreesSum const;
end
virtual void insertconst elemType& insertItem;
binaryTreeTypeconst binaryTreeType& otherTree;
binaryTreeType;
protected:
nodeType root;
private:
void copyTreenodeType &copiedTreeRoot, nodeType otherTreeRoot;
void inordernodeType p const;
void preordernodeType p const;
void postordernodeType p const;
int heightnodeType p const;
int maxint x int y const;
int nodeCountnodeType p const;
For Questions:
int leavesCountnodeType p const;
void swapSubtrees;
void swapSubtreesOfNodenodeType p;
int singleParent const;
int singlePnodeType p const;
int sumnodeType p const;
end
;
Definition of member functions
template
binaryTreeType::binaryTreeType
root NULL;
template
bool binaryTreeType::isEmpty const
return root NULL;
template
void binaryTreeType::inorderTraversal const
inorderroot;
template
void binaryTreeType::preorderTraversal const
preorderroot;
template
void binaryTreeType::postorderTraversal const
postorderroot;
template
int binaryTreeType::treeHeight const
return heightroot;
template
int binaryTreeType::treeNodeCount const
return nodeCountroot;
For Questions:
template
int binaryTreeType::treeLeavesCount const
return leavesCountroot;
template
void binaryTreeType::treeSwapSubtrees
return swapSubtreesroot;
template
void binaryTreeType::treeSwapSubtreesOfNode
return swapSubtreesOfNoderoot;
template
int binaryTreeType::treeSingleParent const
return singleParentroot;
template
int binaryTreeType::treeSingleP const
return singleProot;
end
template
void binaryTreeType::copyTree
nodeType &copiedTreeRoot,
nodeType otherTreeRoot
if otherTreeRoot NULL
copiedTreeRoot NULL;
else
copiedTreeRoot new nodeType;
copiedTreeRootinfo otherTreeRootinfo;
copyTreecopiedTreeRootlLink, otherTreeRootlLink;
copyTreecopiedTreeRootrLink, otherTreeRootrLink;
end copyTree
template
void binaryTreeType::inorder
nodeType p const
if p NULL
inorderplLink;
cout pinfo ;
inorderprLink;
template
void binaryTreeType::preorder
nodeType p const
if p NULL
cout pinfo ;
preorderplLink;
preorderprLink;
template
void binaryTreeType::postorder
nodeType p const
if p NULL
postorderplLink;
postorderprLink;
cout pinfo ;
Overload the assignment operator
template
const binaryTreeType& binaryTreeType::
operatorconst binaryTreeType& otherTree
if this &othe
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started