(Solved) : Lost Need Help Please Goal Assignment Make Provided Testbstcpp Integer Bst Generic Templat Q38270566 . . .
Very Lost!! Need Help Please!!!
Goal: In this assignment, we are to make theprovided testBST.cpp, an integer BST into a generic template BST tohost the following data types:
- Integer,
- String,
- Frac, and
- FeetInches.
The output should look like this:

However, with my code (which I will post below), myoutput looks like this:

I’m having a hard time displaying the Tree diagrams forthe Integer, String, Frac, and FeetInches. Although not featured, Ihave code ready for Frac and FeetInches as well and need Treediagrams for those as well.
Here are the header files:
https://github.com/dvcchern/comsc200/blob/master/m07/Frac.h
https://github.com/dvcchern/comsc200/blob/master/m09/PR17(8th)/FeetInches.h
My Code:
#include<iostream>
#include<vector>
#include “frac.h”
#include “FeetInches.h”
using namespace std;
template <class T>
class Node {
public:
T data;
Node *left, *right, *parent;
Node() {
left = right = parent = NULL;
};
Node(T &value) {
data = value;
};
~Node() {
};
void operator= (const Node<T> &other) {
data = other.data;
};
bool operator< (T &other) {
return (data < other);
};
};
template <class T>
class Tree {
public:
Tree() {
root = NULL;
};
virtual void insert(T &value) {
insertNode(root,NULL,value);
};
virtual Node<T>* find(T &value) {
return searchNode(root,value);
};
virtual bool remove(T &value) {
return deleteNode(root,value);
};
virtual bool operator< (Tree<T> &other) {
return (root->data < other.first()->data);
};
void operator= (Tree<T> &other) {
equalNode(root,other.first());
};
Node<T>*& first() {
return root;
};
virtual void display()
{
displayTree(root);
cout<<endl;
}
virtual void printInorder()
{
displayTree(root);
cout<<endl;
}
protected:
Node<T> *root;
void displayTree(Node<T> * ptr )
{
if(ptr)
{
displayTree(ptr->left);
cout<<ptr->data<<” “;
displayTree(ptr->right);
}
}
void equalNode(Node<T>*& node, Node<T>* value){
if(value != NULL) {
node = new Node<T>();
*node = *value;
if(value->left != NULL)
equalNode(node->left, value->left);
if(value->right != NULL)
equalNode(node->right, value->right);
}
}
void insertNode(Node<T> *&node, Node<T> *parent, T&value) {
if(node == NULL) {
node = new Node<T>();
*node = value;
node->parent = parent;
} else if(value < node->data) {
insertNode(node->left,node,value);
} else
insertNode(node->right,node,value);
};
Node<T>* searchNode(Node<T> *node, T &value){
if(node == NULL)
return NULL;
else if(value == node->data)
return node;
else if(value < node->data)
return searchNode(node->left,value);
else
return searchNode(node->right,value);
};
Node<T>* FindMax(Node<T>* root)
{
if(root==NULL)
return NULL;
while(root->right != NULL)
{
root = root->right;
}
return root;
}
Node<T>* deleteNode(Node<T>* root,T data)
{
if(root==NULL) return root;
else if(data<root->data)
root->left = deleteNode(root->left, data);
else if (data> root->data)
root->right = deleteNode(root->right, data);
else
{
if(root->right == NULL && root->left == NULL)
{
delete root;
root = NULL;
}
else if(root->right == NULL)
{
Node<T>* temp = root;
root= root->left;
delete temp;
}
else if(root->left == NULL)
{
Node<T>* temp = root;
root= root->right;
delete temp;
}
else
{
Node<T>* temp = FindMax(root->left);
root->data = temp->data;
root->left = deleteNode(root->left, temp->data);
}
}
return root;
};
};
template<class T> void test(vector<T> list);
int main() {
vector<int> intPattern {3,8,1,4,6,25,15,16};
test(intPattern);
vector<string> strPattern {
“how”, “many”, “apples”, “did”, “you”, “buy”};
test(strPattern);
Frac array[6]={Frac(1,2),Frac(2,3),Frac(3,4),Frac(5,6),Frac(6,7),Frac(7,8)};
vector<Frac> dest{array[0],array[1],array[2],array[3],array[4],array[5]};
test(dest);
FeetInches array1[6]={FeetInches(1,2),FeetInches(2,3),FeetInches(3,4),FeetInches(5,6),FeetInches(6,7),FeetInches(7,8)};
vector<FeetInches> dest1{array1[0],array1[1],array1[2],array1[3],array1[4],array1[5]};
test(dest1);
}
template<class T>
void test(vector<T> list) {
Tree<T> *b = new Tree<T>;
cout << “Insertion sequence for new tree: n “;
bool first = true;
for(auto x:list) {
b->insert(x);
if(first) first = false;
else cout << “, “;
cout << x;
}
cout << “n Listing Tree nodes in order: n “;
b->display();
cout << “n Show the Original Tree diagram:n”;
b->printInorder();
cout << “n Check whether last inserted Node, (“
<< list[list.size()-1] << “) exists? “
<< ( (b->find(list[list.size()-1]))?”YES”:”NO” )
<< “n Remove fist inserted Noden “;
b->display();
cout << “n Show the final result in Diagram:n”;
b->printInorder();
}
Running /home/ubuntu/workspace/somsc200/Week14/testTemplateBST.cpp Insertion sequence for new tree 3, 8, 1, 4, 6, 25, 15, 16 Listing Tree nodes in order: 13468 15 16 25 Show the Original Tree diagram: 25 1 +16 Check whether last inserted Node, (16) exists? YES Remove fist inserted Node 1346 815 16 25 Show the final result in Diagram: +-25 Insertion sequence for new tree how, many, apples, did, you, buy Listing Tree nodes in order: apples buy did how many you Show the Original Tree diagram: +–you +–many +–how I +-did I I +-buy –apples Check whether last inserted Node, (buy) exists? YES Remove fist inserted Node apples buy did how many you Show the final result in Diagram: +–you +–many +–how I +-did I I +-buy –apples Process exited with code: 0 Insertion sequence for new tree: 3, 8, 1, 4, 6, 25, 15, 16 Listing Tree nodes in order: 1 3 4 6 8 15 16 25 Show the Original Tree diagram: 1 346 8 15 16 25 Check whether last inserted Node, (16) exists? YES Remove fist inserted Node 1 346 8 15 16 25 Show the final result in Diagram: 1 346 8 15 16 25 Insertion sequence for new tree: how, many, apples, did, you, buy Listing Tree nodes in order: apples buy did how man y you Show the Original Tree diagram: apples buy did how many you Check whether last inserted Node, (buy) exists? YES Remove fist inserted Node apples buy did how many you Show the final result in Diagram: apples buy did how many you Show transcribed image text
Expert Answer
Answer to Lost Need Help Please Goal Assignment Make Provided Testbstcpp Integer Bst Generic Templat Q38270566 . . .
OR