Question: Implement the countLeaves function in the binaryTree.h file. Use the following files to create a program to test the new function. #ifndef H _ binaryTree
Implement the countLeaves function in the binaryTree.h file. Use the following files to create a program to test the new function.
#ifndef HbinaryTree
#define HbinaryTree
#include
using namespace std;
template
struct nodeType
elemType info;
nodeType lLink;
nodeType rLink;
;
template
class binaryTreeType
public:
const binaryTreeType& operator
const binaryTreeType&;
bool isEmpty const;
void inorderTraversal const;
void preorderTraversal const;
void postorderTraversal const;
int treeHeight const;
int treeNodeCount const;
int treeLeavesCount const;
void destroyTree; virtual bool searchconst elemType& searchItem const ;
virtual void insertconst elemType& insertItem;
virtual void deleteNodeconst elemType& deleteItem;
binaryTreeTypeconst binaryTreeType& otherTree;
binaryTreeType;
~binaryTreeType;
protected:
nodeType root;
private:
void copyTreenodeType &copiedTreeRoot,
nodeType otherTreeRoot;
void destroynodeType &p;
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;
int leavesCountnodeType p const;
;
template
bool binaryTreeType::isEmpty const
return root nullptr;
template
binaryTreeType::binaryTreeType
root nullptr;
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;
template
int binaryTreeType::treeLeavesCount const
return leavesCountroot;
template
void binaryTreeType::inorder
nodeType p const
if p nullptr
inorderplLink;
cout pinfo ;
inorderprLink;
template
void binaryTreeType::preorder
nodeType p const
if p nullptr
cout pinfo ;
preorderplLink;
preorderprLink;
template
void binaryTreeType::postorder
nodeType p const
if p nullptr
postorderplLink;
postorderprLink;
cout pinfo ;
template
int binaryTreeType::height
nodeType p const
if p nullptr
return ;
else
return maxheightplLink heightprLink;
template
int binaryTreeType::maxint x int y const
if x y
return x;
else
return y;
template
void binaryTreeType::copyTree
nodeType &copiedTreeRoot,
nodeType otherTreeRoot
if otherTreeRoot nullptr
copiedTreeRoot nullptr;
else
copiedTreeRoot new nodeType;
copiedTreeRootinfo otherTreeRootinfo;
copyTreecopiedTreeRootlLink, otherTreeRootlLink;
copyTreecopiedTreeRootrLink, otherTreeRootrLink;
end copyTree
template
void binaryTreeType::destroynodeType &p
if p nullptr
destroyplLink;
destroyprLink;
delete p;
p nullptr;
template
void binaryTreeType::destroyTree
destroyroot;
template
binaryTreeType::binaryTreeType
const binaryTreeType& otherTree
if otherTreeroot nullptrotherTree is empty
root nullptr;
else
copyTreeroot otherTree.root;
template
binaryTreeType::~binaryTreeType
destroyroot;
template
const binaryTreeType& binaryTreeType::
operatorconst binaryTreeType& otherTree
if this &otherTree
if root nullptr
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
