Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need c++ format; need implement search and remove function BSTNode * BST ::search(const K& key) Should return a pointer to the found node, if not
need c++ format;
need implement search and remove function
- BSTNode
* BST ::search(const K& key) - Should return a pointer to the found node, if not found return nullptr.
- bool BST
::remove(const K& key) - Leave this function to implement to last. However the destroy function should be implemented no matter what since we are using dynamic memory.
data.h *************************************** #include#include template class Data { public: explicit Data(const T& myData) : data(myData) {} Data() = delete; T getData() const { return data; } void print(std::ostream& outfile = std::cout) { outfile include template BSTNode delete data; ) K getKey) const return key: h DatacT>getData) const freturn data; ) void setLeft (BSTNode K,T* const node) left- node; void setRight(BSTNodeK,T>* const node) { right node; } BSTNode & rhs) const return key * left = nullptr; BSTNode & operator-(const BSTNode6) -delete ; template bool remove (const K& key) // Implement remove node EST() { destroy(root); } BSTNode K,T* rootnullptr template * BST * subtree) template void BSTK, Trint (std::ostream& outfile, const BSTNode T,subtree) const template typename K, typename bool BST K, T remove(const K& key) template typename typename BSTNodeK,T BSTK,Tsearch(const K& key) nain.cpp #include "BST.h" int main BSTint,int> tree: tree.add(50, 50) tree.add (40, 40); tree. add(60, 60); tree.add(55, 55); tree.print(); return O 0: include template BSTNode delete data; ) K getKey) const return key: h DatacT>getData) const freturn data; ) void setLeft (BSTNode K,T* const node) left- node; void setRight(BSTNodeK,T>* const node) { right node; } BSTNode & rhs) const return key * left = nullptr; BSTNode & operator-(const BSTNode6) -delete ; template bool remove (const K& key) // Implement remove node EST() { destroy(root); } BSTNode K,T* rootnullptr template * BST * subtree) template void BSTK, Trint (std::ostream& outfile, const BSTNode T,subtree) const template typename K, typename bool BST K, T remove(const K& key) template typename typename BSTNodeK,T BSTK,Tsearch(const K& key) nain.cpp #include "BST.h" int main BSTint,int> tree: tree.add(50, 50) tree.add (40, 40); tree. add(60, 60); tree.add(55, 55); tree.print(); return O 0
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