Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#ifndef BINARYSEARCHTREE _ H #define BINARYSEARCHTREE _ H #include #include #include #include #includebstnode.h / / Node implementation: Implemented template class Node { public: Node
#ifndef BINARYSEARCHTREEH
#define BINARYSEARCHTREEH
#include
#include
#include
#include
#include"bstnode.h
Node implementation: Implemented
template
class Node
public:
NodeType v Node l Node r :valv ll rr
Node :Node nullptr, nullptr
Node left return l;
Node right return r;
void leftNode lft l lft;
void rightNode rhtr rht;
Type value return val;
void valueType v val v;
private:
Type val;
Node lr;
;
template
class BinarySearchTree
public:
Public Interface Functions: All of these are implemented
BinarySearchTree;
~BinarySearchTree;
void printInorder;
void printPostorder;
void printPreorder;
void insertType value;
void removeType value;
Type min const;
Type max const;
int height const;
bool searchType value const;
bool empty const;
void printTree const;
void report const;
private:
Member variable root
Node root;
Auxillary recursive bst functions
public interface functions call these
You will implement these functions.
Tree traversal, second parameter is a "function" with
return type void and parameter Node ie:
void processNode
void inorderNode node, std::function proc;
void preorderNode node, std::function proc;
void postorderNode node, std::function proc;
Node minNode node const;
Node maxNode node const;
int heightNode node const;
Node insertNode node Type value;
bool searchNode node Type value const;
Node removeNode node Type value;
void printTreeNode node int space const;
;
Binary Search Tree Function Implementations
Public Interface functions
Completley Implemented, nothing to do These functions
call the recursive helper functions you will implement
below.
Constructor
template
BinarySearchTree::BinarySearchTree :rootnullptr
Destructor
template
BinarySearchTree::~BinarySearchTree
Use the post order traversal to delete the nodes.
lambda function to delete a node n:
Node ndelete n;
postorderrootNode ndelete n; ;
template
void BinarySearchTree::printInorder
Use inorder traversal to print items in a node in the tree.
lambda function to print the value in a node:
lambda to printNode nstd::cout nvalue std::endl;
inorderrootNode nstd::cout nvalue; ;
std::cout std::endl;
template
void BinarySearchTree::printPreorder
Use pre order traversal to print items in a node in the tree.
lambda function to print the value in a node:
lambda to printNode nstd::cout nvalue std::endl;
preorderrootNode nstd::cout nvalue; ;
std::cout std::endl;
template
void BinarySearchTree::printPostorder
Use post order traversal to print items in a node in the tree.
lambda function to print the value in a node:
lambda to printNode nstd::cout nvalue std::endl;
postorderrootNode nstd::cout nvalue; ;
std::cout std::endl;
template
void BinarySearchTree::insertType value
root insertroot value;
template
void BinarySearchTree::removeType value
root removeroot value;
template
Type BinarySearchTree::min const
assertroot nullptr;
Node node minroot;
return nodevalue;
template
Type BinarySearchTree::max const
assertroot nullptr;
Node node maxroot;
return nodevalue;
template
int BinarySearchTree::height const
return heightroot;
template
bool BinarySearchTree::searchType value const
return searchroot value;
template
bool BinarySearchTree::empty const
return root nullptr;
template
void BinarySearchTree::printTree const
printTreeroot;
Private Recursive Functions: You Implement These.
Inorder Traversal: Implemented so you can see how passing a function into
another function works, other traversals remain for you to implement. the second
p
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