Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use the linked approach implement the BST ADT, implement all the function

ID: 3847670 • Letter: P

Question

Please use the linked approach implement the BST ADT, implement all the functions in the BSTree.cpp. Please use C++ programming

//////////////////////////////////////////////////////////////

#include "BSTree.h"

template <typename DataType, class KeyType>
BSTree<DataType, KeyType>::BSTreeNode::BSTreeNode ( const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr )
{
}

template < typename DataType, class KeyType >
BSTree<DataType, KeyType>::BSTree ()
{
   root = 0;
}

template < typename DataType, class KeyType >
BSTree<DataType, KeyType>::BSTree ( const BSTree<DataType,KeyType>& other )
{
}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>:: copyTree(const BSTree<DataType, KeyType> &otherTree)
{
   copyTreeHelper(root, otherTree.root);
}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>:: copyTreeHelper(BSTreeNode *&p, const BSTreeNode *otherPtr)
{
   if (p != 0)
   {
       p = new BSTreeNode(otherPtr->dataItem, 0, 0);
       copyTreeHelper(p->left, otherPtr->left);
       copyTreeHelper(p->right, otherPtr->right);
   }
}

template < typename DataType, class KeyType >
BSTree<DataType, KeyType>& BSTree<DataType, KeyType>:: operator= ( const BSTree<DataType,KeyType>& other )
{

}

template < typename DataType, class KeyType >
BSTree<DataType, KeyType>::~BSTree ()
{

}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>::insert ( const DataType& newDataItem )
{

}

template < typename DataType, class KeyType >
bool BSTree<DataType, KeyType>::retrieve ( const KeyType& searchKey, DataType& searchDataItem ) const
{
   return false;
}

template < typename DataType, class KeyType >
bool BSTree<DataType, KeyType>::remove ( const KeyType& deleteKey )
{
   return false;
}

template < typename DataType, class KeyType >
bool BSTree<DataType, KeyType>::removeHelper(BSTreeNode *&p, const KeyType& deleteKey)
{

}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>::writeKeys () const
{

}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>::writeLTHelper(BSTreeNode *p, const KeyType& searchKey) const
{

}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>::clear ()
{

}

template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>::clearHelper(BSTreeNode *p)
{

}

template < typename DataType, class KeyType >
bool BSTree<DataType, KeyType>::isEmpty () const
{
   return false;
}

template < typename DataType, class KeyType >
int BSTree<DataType, KeyType>::getHeight () const
{
   return -1;
}

template < typename DataType, class KeyType >
int BSTree<DataType, KeyType>::getHeightHelper(BSTreeNode *p) const
{

}


template < typename DataType, class KeyType >
int BSTree<DataType, KeyType>::getCount () const
{
   return -1;
}

template < typename DataType, class KeyType >
int BSTree<DataType, KeyType>::getCountHelper(BSTreeNode *p) const
{

}


template < typename DataType, class KeyType >
void BSTree<DataType, KeyType>::writeLessThan ( const KeyType& searchKey ) const
{
}


#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 <stdexcept>
#include <iostream>

using namespace std;

template < typename DataType, class KeyType > // DataType : tree data item
class BSTree // KeyType : key field
{
public:

   // Constructor
   BSTree(); // Default constructor
   BSTree(const BSTree<DataType, KeyType>& other); // Copy constructor
   BSTree& operator= (const BSTree<DataType, KeyType>& other);
   // Overloaded assignment operator

   // 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 < searchKey

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<DataType, KeyType> &otherTree);
   void copyTreeHelper(BSTreeNode *&p, const BSTreeNode *otherPtr);

   // Data member
   BSTreeNode *root; // Pointer to the root node
};

#endif   // define BSTREE_H

Explanation / Answer

#include "BSTree.h"
template &lt;typename DataType, category KeyType&gt;
BSTree&lt;DataType, KeyType&gt;::BSTreeNode::BSTreeNode ( const DataType &amp;nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr )

template &lt; typename DataType, category KeyType &gt;
BSTree&lt;DataType, KeyType&gt;::BSTree ()

template &lt; typename DataType, category KeyType &gt;
BSTree&lt;DataType, KeyType&gt;::BSTree ( const BSTree&lt;DataType,KeyType&gt;&amp; alternative )

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;:: copyTree(const BSTree&lt;DataType, KeyType&gt; &amp;otherTree)

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;:: copyTreeHelper(BSTreeNode *&amp;p, const BSTreeNode *otherPtr)

}
template &lt; typename DataType, category KeyType &gt;
BSTree&lt;DataType, KeyType&gt;&amp; BSTree&lt;DataType, KeyType&gt;:: operator= ( const BSTree&lt;DataType,KeyType&gt;&amp; alternative )

template &lt; typename DataType, category KeyType &gt;
BSTree&lt;DataType, KeyType&gt;::~BSTree ()

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;::insert ( const DataType&amp; newDataItem )

template &lt; typename DataType, category KeyType &gt;
bool BSTree&lt;DataType, KeyType&gt;::retrieve ( const KeyType&amp; searchKey, DataType&amp; searchDataItem ) const
come back false;
}
template &lt; typename DataType, category KeyType &gt;
bool BSTree&lt;DataType, KeyType&gt;::remove ( const KeyType&amp; deleteKey )
come back false;
}
template &lt; typename DataType, category KeyType &gt;
bool BSTree&lt;DataType, KeyType&gt;::removeHelper(BSTreeNode *&amp;p, const KeyType&amp; deleteKey)

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;::writeKeys () const

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;::writeLTHelper(BSTreeNode *p, const KeyType&amp; searchKey) const

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;::clear ()

template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;::clearHelper(BSTreeNode *p)

template &lt; typename DataType, category KeyType &gt;
bool BSTree&lt;DataType, KeyType&gt;::isEmpty () const
come back false;
}
template &lt; typename DataType, category KeyType &gt;
int BSTree&lt;DataType, KeyType&gt;::getHeight () const

template &lt; typename DataType, category KeyType &gt;
int BSTree&lt;DataType, KeyType&gt;::getHeightHelper(BSTreeNode *p) const


template &lt; typename DataType, category KeyType &gt;
int BSTree&lt;DataType, KeyType&gt;::getCount () const

template &lt; typename DataType, category KeyType &gt;
int BSTree&lt;DataType, KeyType&gt;::getCountHelper(BSTreeNode *p) const


template &lt; typename DataType, category KeyType &gt;
void BSTree&lt;DataType, KeyType&gt;::writeLessThan ( const KeyType&amp; searchKey ) const


#include "show9.cpp"
/////////////////////////////////////////////////////////////////////////////////////////
Class declarations for the joined implementation of the Binary
// Search Tree ADT -- together with the algorithmic helpers of the
// public member functions
//
//--------------------------------------------------------------------
#ifndef BSTREE_H
#define BSTREE_H
#include &lt;stdexcept&gt;
#include &lt;iostream&gt;
using namespace std;
template &lt; typename DataType, category KeyType &gt; // DataType : tree information item
class BSTree // KeyType : key field
builder
BSTree(); // Default creator
BSTree(const BSTree&lt;DataType, KeyType&gt;&amp; other); // Copy creator
BSTree&amp; operator= (const BSTree&lt;DataType, KeyType&gt;&amp; other);
// full assignment operator
// Destructor
~BSTree();
// Binary search tree manipulation operations
void insert(const DataType&amp; newDataItem); // Insert information item
bool retrieve(const KeyType&amp; searchKey, DataType&amp; searchDataItem) const;
// Retrieve information item
bool remove(const KeyType&amp; deleteKey); // take away information item
void writeKeys() const; // Output keys
void clear(); // Clear tree
// Binary search tree standing operations
bool isEmpty() const; // Tree is empty
// !! isFull() has been retired. Not terribly helpful in a very joined structure.
// Output the tree structure -- utilized in testing/debugging
void showStructure() const;
// In-lab operations
int getHeight() const; // Height of tree
int getCount() const; // variety of nodes in tree
void writeLessThan(const KeyType&amp; searchKey) const; // Output keys &lt; searchKey
protected:
category BSTreeNode // Inner category: helper for the BSTree class
{
public:
// creator
BSTreeNode(const DataType &amp;nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr);
// information members
DataType informationItem; // Binary search tree data item
BSTreeNode *left, // Pointer to the left kid
*right; // Pointer to the correct kid
};
// algorithmic helpers for the general public member functions -- insert
// prototypes of those functions here.
void insertHelper(BSTreeNode *&amp;p, const DataType &amp;newDataItem);
bool retrieveHelper(BSTreeNode *p, const KeyType&amp; searchKey, DataType &amp;searchDataItem) const;
bool removeHelper(BSTreeNode *&amp;p, const KeyType&amp; deleteKey);
// cutRightmose utilized in one implementation of take away.
void cutRightmost(BSTreeNode *&amp;r, BSTreeNode *&amp;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&amp; searchKey) const;
void copyTree(const BSTree&lt;DataType, KeyType&gt; &amp;otherTree);
void copyTreeHelper(BSTreeNode *&amp;p, const BSTreeNode *otherPtr);
// information member
BSTreeNode *root; // Pointer to the basis node
};
#endif // outline BSTREE_H