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 to traverse the tree - read the implementation notes on using helper functions.

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

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/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:
If you have any problems here, will help you please let me know.

BSTree.cpp
#include "BSTree.h"

template <typename DataType, class KeyType>
BSTree<DataType, KeyType>::BSTree () { // Default constructor
root = NULL;
counter = 0;
   cursor = NULL;
}


template <typename DataType, class KeyType>
BSTree<DataType, KeyType>::BSTree ( const BSTree<DataType,KeyType>& other ) { // Copy constructor
   *this = other;
}

template <typename DataType, class KeyType>
BSTree<DataType, KeyType>& BSTree<DataType, KeyType>::operator= ( const BSTree<DataType,KeyType>& other ) {
   if (this != other) {
       clear();
       root = assignHelper(root);
   }   
   return *this;
}

template <typename DataType, class KeyType>
typename BSTree<DataType,KeyType>::BSTreeNode* BSTree<DataType, KeyType>::assignHelper(BSTreeNode* copy) {
   BSTreeNode* pointer;
   if (copy != NULL) {
       pointer = new BSTreeNode(copy.dataItem, copy->left, copy->right);
   }
   else {
       pointer = NULL;
   }
   return pointer;
}

// Destructor
template <typename DataType, class KeyType>
BSTree<DataType, KeyType>::~BSTree () {
clear();
root = NULL;   
counter = 0;
}

   //searches the tree
template <typename DataType, class KeyType>
char BSTree<DataType, KeyType>::search(KeyType data){
   char direction;
   if(data < cursor->dataItem.getKey() && cursor->left != NULL){
       cursor = cursor->left;
       direction = search(data);
   }
   else if(data > cursor->dataItem.getKey() && cursor->right !=NULL){
       cursor = cursor->right;
       direction = search(data);
   }
   else{
       if(data == cursor->dataItem.getKey())
           direction = 'n';
       else if(data < cursor->dataItem.getKey())
           direction = 'l';
       else if(data > cursor->dataItem.getKey())
           direction = 'r';
   }
   return direction;
}

// Binary search tree manipulation operations
template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::insert ( const DataType& newDataItem ) { // Insert data item
if (isEmpty()) {
root = new BSTreeNode(newDataItem, NULL, NULL);
counter++;
}
else {
//need to sort into correct node position within tree
   cursor = root;
   char direction = search( newDataItem.getKey());
   if(direction == 'l')
           cursor->left = new BSTreeNode(newDataItem, NULL, NULL);
   else if(direction == 'r')
           cursor->right = new BSTreeNode(newDataItem, NULL, NULL);
   else
           cout << "Cannot insert duplicates of the same item!\n\n";
counter++;
}
   cursor = root;
}

template <typename DataType, class KeyType> //Retrieve data item
bool BSTree<DataType, KeyType>::retrieve ( const KeyType& searchKey, DataType& searchDataItem ) {
   cursor = root;
   char direction = search(searchKey);
if (direction == 'n') {
       searchDataItem = cursor->dataItem;
       return true;
   }
   else {
       return false;
   }
}

//---------------------------------------------------------
template <typename DataType, class KeyType>
bool BSTree<DataType, KeyType>::remove ( const KeyType& deleteKey) { // Remove data item
if (isEmpty()) {
return false;
cout << "Tree is empty! Cannot remove." << endl;
}
/*else {
return removeHelper(deleteKey, root);
}*/
}

/*template <typename DataType, class KeyType>
bool BSTree<DataType, KeyType>::removeHelper(KeyType deleteKey, BSTreeNode* lostNode) {
if (lostNode == NULL) {
return;
}
if (deleteKey < lostNode->dataItem.getKey()) {
removeHelper(deleteKey, lostNode->left);   
return true;   
}
else if(lostNode->dataItem.getKey() < deleteKey) {
removeHelper(deleteKey, lostNode->right);
return true;   
}
else if (lostNode->left != NULL && lostNode->right != NULL) {
lostNode->dataItem = findMin(lostNode->right)->dataItem.getKey();
removeHelper(lostNode->dataItem, lostNode->right);   
return true;
}
else {
BSTreeNode *oldNode = lostNode;
lostNode = (lostNode->left != NULL) ? lostNode->left : lostNode->right;
delete oldNode;   
return true;
}
}*/

/*template <typename DataType, class KeyType>
typename BSTree<DataType,KeyType>::BSTreeNode* BSTree<DataType, KeyType>::findMin(BSTreeNode* node) {
if (node == NULL) {
return NULL;
}
if (node->left == NULL) {
return node;
}
return findMin(node->left);
}*/

template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::writeKeys () const { // Output keys
if (isEmpty()) {
cout << "Empty tree!" << endl;
}
else {
writeKeysHelper(root);
}
}

template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::writeKeysHelper(BSTreeNode *node) const {
if (node != NULL) {
writeKeysHelper(node->left);
cout << node->dataItem.getKey() << endl;
writeKeysHelper(node->right);
}
}

template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::clear () { // Clear tree
if (root == NULL && counter == 0) {
cout << "Tree is already empty!" << endl;
}
else {
helpClear(root);
root = NULL;
counter = 0;
}
}

template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::helpClear(BSTreeNode* gone) {
if (gone != NULL) {
helpClear(gone->left);
helpClear(gone->right);
delete gone;
}
gone = NULL;
counter = 0;
}


// Binary search tree status operations
template <typename DataType, class KeyType>
bool BSTree<DataType, KeyType>::isEmpty () const { // Tree is empty
// !! isFull() has been retired. Not very useful in a linked structure.
if (root == NULL && counter == 0) {
return true;
}
else {
return false;
}
}

// Output the tree structure -- used in testing/debugging
template < typename DataType, typename KeyType >
void BSTree<DataType,KeyType>:: showStructure () const

// Outputs the keys in a binary search tree. The tree is output
// rotated counterclockwise 90 degrees from its conventional
// orientation using a "reverse" inorder traversal. This operation is
// intended for testing and debugging purposes only.

{
if ( root == 0 )
cout << "Empty tree" << endl;
else
{
cout << endl;
showHelper(root,1);
cout << endl;
}
}

// In-lab operations
template <typename DataType, class KeyType>
int BSTree<DataType, KeyType>::getHeight () { // Height of tree
int height;
if (isEmpty()) {
height = 0;
}
else {
height = heightHelper(root);
}
return height;
}

template <typename DataType, class KeyType>
int BSTree<DataType, KeyType>::heightHelper(BSTreeNode* heightNode) {
if (heightNode != NULL) {
return (max(heightHelper(heightNode->left), heightHelper(heightNode->right))+1);
}
   else {
       return 0;
   }
}

template <typename DataType, class KeyType>
int BSTree<DataType, KeyType>::getCount () const {           // Number of nodes in tree
return counter;
}

//---------------------------------------------------------------
template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::writeLessThan ( const KeyType& searchKey ) { // Output keys < searchKey
if (isEmpty()) {
cout << "Tree is empty!" << endl;
}
else {
writeLessHelper(root, searchKey);
}
}

//--------------------------------------------------------------------
template <typename DataType, class KeyType>
void BSTree<DataType, KeyType>::writeLessHelper(BSTreeNode* pointer, KeyType searchKey) {
if (pointer == NULL) {
return;
}
else {if (pointer->dataItem.getKey() >= searchKey) {
writeLessHelper(pointer->left, searchKey);
}
else {
pointer = pointer->left;
cout << pointer->dataItem.getKey() << endl;
writeLessHelper(pointer->right, searchKey);
}   
}
}
  
// Constructor
template <typename DataType, class KeyType>
BSTree<DataType, KeyType>::BSTreeNode::BSTreeNode( const DataType &nodeDataItem, BSTreeNode *leftPtr, BSTreeNode *rightPtr ) {
dataItem = nodeDataItem;
left = leftPtr;
right = rightPtr;   
}

// Recursive helpers for the public member functions -- insert
// prototypes of these functions here.
  
  
template <typename DataType, class KeyType>
void BSTree<DataType,KeyType>:: showHelper ( BSTreeNode *p, int level) const

// Recursive helper for showStructure.
// Outputs the subtree whose root node is pointed to by p.
// Parameter level is the level of this node within the tree.

{
int j; // Loop counter

if ( p != 0 )
{
showHelper(p->right,level+1); // Output right subtree
for ( j = 0 ; j < level ; j++ ) // Tab over to level
cout << "\t";
cout << " " << p->dataItem.getKey(); // Output key
if ( ( p->left != 0 ) && // Output "connector"
( p->right != 0 ) )
cout << "<";
else if ( p->right != 0 )
cout << "/";
else if ( p->left != 0 )
cout << "\\";
cout << endl;
showHelper(p->left,level+1); // Output left subtree
}
}

BSTree.h

#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

//   BSTree& traverse();
//   void search(KeyType data, char& direction = 'l');

   char search(KeyType data);
   void insert ( const DataType& newDataItem ); // Insert data item
   //bool retrieve (KeyType searchKey, DataType& searchDataItem ) const;
bool retrieve ( const KeyType& searchKey, DataType& searchDataItem );
// 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 (); // Height of tree
int getCount () const;           // Number of nodes in tree
void writeLessThan ( const KeyType& searchKey ); // 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 showHelper ( BSTreeNode *p, int level ) const;
//BSTreeNode* findMin(BSTreeNode* node)const;
void writeKeysHelper(BSTreeNode *node) const;
    void helpClear(BSTreeNode* gone);  
int heightHelper(BSTreeNode* heightNode);
   typename BSTree<DataType, KeyType>::BSTreeNode* assignHelper(BSTreeNode* copy);
   void writeLessHelper(BSTreeNode* pointer, KeyType searchkey);
   //bool removeHelper(KeyType deleteKey, BSTreeNode* lostNode);
   //typename BSTree<DataType,KeyType>::BSTreeNode* findMin(BSTreeNode* node) {
  
   // Data member
   BSTreeNode *cursor;
BSTreeNode *root; // Pointer to the root node
int counter; //helper member
};

#endif   // define BSTREE_H

driver.cpp
using namespace std;

#include <iostream>
#include "BSTree.cpp"

void print_help();

//--------------------------------------------------------------------
// Declaration for the binary search tree data item class
//--------------------------------------------------------------------

class TestData
{
public:

void setKey ( int newKey )
{ keyField = newKey; } // Set the key

int getKey () const
{ return keyField; } // Returns the key

private:

int keyField; // Key for the data item
};

int main()
{
BSTree<TestData,int> testTree; // Test binary search tree
TestData testData; // Binary search tree data item
int inputKey; // User input key
char cmd; // Input command

print_help();

do
{
testTree.showStructure(); // Output tree

cout << endl << "Command: "; // Read command
cin >> cmd;
if ( cmd == '+' || cmd == '?' ||
cmd == '-' || cmd == '<' )
cin >> inputKey;

switch ( cmd )
{
case 'P' : case 'p' :
print_help();
break;

case '+' : // insert
testData.setKey(inputKey);
cout << "Insert : key = " << testData.getKey()
<< endl;
testTree.insert(testData);
break;

case '?' : // retrieve
if ( testTree.retrieve(inputKey,testData) )
cout << "Retrieved : getKey = "
<< testData.getKey() << endl;
else
cout << "Not found" << endl;
break;

case '-' : // remove
if ( testTree.remove(inputKey) )
cout << "Removed data item" << endl;
else
cout << "Not found" << endl;
break;

case 'K' : case 'k' : // writeKeys
cout << "Keys:" << endl;
testTree.writeKeys();
break;

case 'C' : case 'c' : // clear
cout << "Clear the tree" << endl;
testTree.clear();
break;

case 'E' : case 'e' : // empty
if ( testTree.isEmpty() )
cout << "Tree is empty" << endl;
else
cout << "Tree is NOT empty" << endl;
break;


case 'G' : case 'g' :   
cout << "Tree nodes count = " << testTree.getCount() << endl;
break;

case 'H' : case 'h' :   
cout << "Tree height = " << testTree.getHeight() << endl;
break;

       case '<' :
cout << "Keys < " << inputKey << " : " << endl;
testTree.writeLessThan(inputKey);
cout << endl;
break;


case 'Q' : case 'q' : // Quit test program
break;

default : // Invalid command
cout << "Inactive or invalid command. 'P' prints help." << endl;
}
}
while ( cin && ( cmd != 'Q' ) && ( cmd != 'q' ) );
  
if ( !cin ) {
   cerr << "Error in console input. Exiting." << endl;
}

return 0;
}

//--------------------------------------------------------------------

void print_help() {
cout << endl << "Commands:" << endl;
cout << " P : [P]rint Help (displays this message)" << endl;
cout << " +key : Insert (or update) data item (use integers)" << endl;
cout << " ?key : Retrieve data item" << endl;
cout << " -key : Remove data item" << endl;
cout << " K : Write keys in ascending order" << endl;
cout << " C : Clear the tree" << endl;
cout << " E : Empty tree?" << endl;
cout << " G : Get count of nodes (Active : Tester 1)" << endl;
   cout << " H : Height (Active : Tester 2) " << endl;
   cout << " Q : Quit the test program" << endl;
cout << endl;
}

Add a comment
Know the answer?
Add Answer to:
Please use the linked approach implement the BST ADT, implement all the functions in the BSTree.cpp....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • - implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h"...

    - implement the Stack ADT using array – based approach. Use C++ program language #include "StackArray.h" template <typename DataType> StackArray<DataType>::StackArray(int maxNumber) { } template <typename DataType> StackArray<DataType>::StackArray(const StackArray& other) { } template <typename DataType> StackArray<DataType>& StackArray<DataType>::operator=(const StackArray& other) { } template <typename DataType> StackArray<DataType>::~StackArray() { } template <typename DataType> void StackArray<DataType>::push(const DataType& newDataItem) throw (logic_error) { } template <typename DataType> DataType StackArray<DataType>::pop() throw (logic_error) { } template <typename DataType> void StackArray<DataType>::clear() { } template <typename DataType> bool StackArray<DataType>::isEmpty() const {...

  • In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the...

    In this assignment, you will implement a sort method on singly-linked and doubly-linked lists. Implement the following sort member function on a singly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); Implement the following sort member function on a doubly-linked list: void sort(bool(*comp)(const T &, const T &) = defaultCompare); The sort(…) methods take as a parameter a comparator function, having a default assignment of defaultCompare, a static function defined as follows: template <typename T> static bool defaultCompare(const...

  • Review the Stack implementation with Vector, and implement/answer the following methods. Stack One of the principles...

    Review the Stack implementation with Vector, and implement/answer the following methods. Stack One of the principles of good programming is to reuse existing code whenever practical. If you can reuse existing code, you don't need to spend the time to rewrite it. Code used previously has also been debugged, and will likely contain fewer errors. One of the easiest ways to create a container is to leverage an existing data type to build a new abstraction. In this lesson we...

  • Use a B-Tree to implement the set.h class. #ifndef MAIN_SAVITCH_SET_H #define MAIN_SAVITCH_SET_H #include <cstdlib> // Provides...

    Use a B-Tree to implement the set.h class. #ifndef MAIN_SAVITCH_SET_H #define MAIN_SAVITCH_SET_H #include <cstdlib> // Provides size_t namespace main_savitch_11 { template <class Item> class set { public: // TYPEDEFS typedef Item value_type; // CONSTRUCTORS and DESTRUCTOR set( ); set(const set& source); ~set( ) { clear( ); } // MODIFICATION MEMBER FUNCTIONS void operator =(const set& source); void clear( ); bool insert(const Item& entry); std::size_t erase(const Item& target); // CONSTANT MEMBER FUNCTIONS std::size_t count(const Item& target) const; bool empty( ) const...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • I'm just not sure how to tackle all the template class this header wants me to...

    I'm just not sure how to tackle all the template class this header wants me to write. I got this far into making the template for public and private and would like help on the template functions. Thank you! This is in C++ by the way. #include <iostream> #include <cassert> using namespace std; #ifndef ARRAYLIST_H #define ARRAYLIST_H template<typename T> class arrayList { public:    arrayList(); //Constructor with default parameter. //Sets maxSize = 100 and length = 0 if no parameter...

  • Consider the class specifications for the Binary Tree class and BinarySearch Tree class below: // Binary...

    Consider the class specifications for the Binary Tree class and BinarySearch Tree class below: // Binary Tree.h #include <iostream> using namespace std; //Definition of the Node template <class elemType struct TreeNode { elemType data; TreeNode<elemType> *left; TreeNode<elemType *right; }; //Definition of class Binary Tree template <class elemType> class Binary Tree { protected: TreeNode<elemType> *root; public: BinaryTree(); BinaryTreel const BinaryTree<elemType>& otherTree); -Binary Tree(): bool is Empty() const; virtual bool search(const elemTypes searchItem) const = 0; virtual void insert(const elemTypek insertItem) =...

  • Consider the partial implementation of a Binary Search Tree (BST) class. For simplicity, each Node stores...

    Consider the partial implementation of a Binary Search Tree (BST) class. For simplicity, each Node stores only the key. Add a public member function to class BST that returns the largest absolute value in the tree. The language is C++ Want the height #4 Coding [6 points] Consider the partial implementation of a Binary Search Tree (BST) class. For simplicity, each Node stores only the key. Add a public member function to class BST that returns the height of the...

  • Binary Tree Template Write your own version of a class template that will create a binary...

    Binary Tree Template Write your own version of a class template that will create a binary tree that can hold values of any data type. Demonstrate the class with a driver program. Place your binary tree template in it's own header file, Btree.h. Include methods for the following: inserting new values into the tree removing nodes from the tree searching the tree returning the number of nodes in the tree displaying the contents of the tree using preorder traversal Your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT