Question
Please use the linked approach implement the BST ADT, implement all the functions in the BSTree.cpp. Add the ouput of the implementation. use recursive functions
Please use the linked approach implement the BST ADT, implement all the functions in the BSTree.cpp. Add the ouput of the implementation.
use recursive functions to traverse the tree - read the implementation notes on using helper functions.
Please use C++ programming
//////////////////////////////////////////////////////////////
#include "BSTree.h"
template
template BSTree
template BSTree
template void BSTree
template void BSTree
template BSTree
}
template BSTree
}
template void BSTree
}
template bool BSTree
template bool BSTree
template bool BSTree
}
template void BSTree
}
template void BSTree
}
template void BSTree
}
template void BSTree
}
template bool BSTree
template int BSTree
template int BSTree
}
template int BSTree
template int BSTree
}
template void BSTree
#include "show9.cpp"
/////////////////////////////////////////////////////////////////////////////////////////
Class declarations for the linked implementation of the Binary // Search Tree ADT -- including the recursive helpers of the // public member functions // //--------------------------------------------------------------------
#ifndef BSTREE_H #define BSTREE_H
#include
using namespace std;
template // DataType : tree data item class BSTree // KeyType : key field { public:
// Constructor BSTree(); // Default constructor BSTree(const BSTree
// Destructor ~BSTree();
// Binary search tree manipulation operations void insert(const DataType& newDataItem); // Insert data item bool retrieve(const KeyType& searchKey, DataType& searchDataItem) const; // Retrieve data item bool remove(const KeyType& deleteKey); // Remove data item void writeKeys() const; // Output keys void clear(); // Clear tree
// Binary search tree status operations bool isEmpty() const; // Tree is empty // !! isFull() has been retired. Not very useful in a linked structure.
// Output the tree structure -- used in testing/debugging void showStructure() const;
// In-lab operations int getHeight() const; // Height of tree int getCount() const; // Number of nodes in tree void writeLessThan(const KeyType& searchKey) const; // Output keys
protected:
class BSTreeNode // Inner class: facilitator for the BSTree class { public:
// Constructor BSTreeNode(const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr);
// Data members DataType dataItem; // Binary search tree data item BSTreeNode *left, // Pointer to the left child *right; // Pointer to the right child };
// Recursive helpers for the public member functions -- insert // prototypes of these functions here. void insertHelper(BSTreeNode *&p, const DataType &newDataItem); bool retrieveHelper(BSTreeNode *p, const KeyType& searchKey, DataType &searchDataItem) const; bool removeHelper(BSTreeNode *&p, const KeyType& deleteKey); // cutRightmose used in one implementation of remove. void cutRightmost(BSTreeNode *&r, BSTreeNode *&delPtr); void writeKeysHelper(BSTreeNode *p) const; void clearHelper(BSTreeNode *p); void showHelper(BSTreeNode *p, int level) const; int getHeightHelper(BSTreeNode *p) const; int getCountHelper(BSTreeNode *p) const; void writeLTHelper(BSTreeNode *p, const KeyType& searchKey) const; void copyTree(const BSTree
// Data member BSTreeNode *root; // Pointer to the root node };
#endif // define BSTREE_H
This is what the ouput is suppose to look like
//////////////////////////////////////////////////////////////////
Enpty tree Command: P Commands P Print Help +key Insert data key Retrieve data key Remove data Write keys in asc order Clear tree Empty tree? Get count of nodes KActive Tester 1 Height Active Tester 2 Kkey Write keys that are key KInactive Tester 3 Q quit the test progran Enpt y tree CAUsers1301595DocumentsWVisual Studio 2012MProjectsMBsTree Debug NBs Tree exe Command +1 Insert key 1 Command +2 Insert key 2 1/ Command +3 Insert key 3 Command: Not found 2/ 1/
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