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

I need help writing this program in C++. Thank You Binary Tree Template Write yo

ID: 3676458 • Letter: I

Question

I need help writing this program in C++. Thank You

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 public interface must include at least the following methods:

-- void insert( T )
-- void remove( T )
-- bool search( T )
-- void preprint()
-- int count()

Where T is a generic parameter ( you can name it anything, I just chose T )

Sample Usage:

BTree<char> b;

b.preprint();
cout << b.count();
b.insert('A');
cout << b.search('A');
b.remove('A');

Should be able to write statements like this in a program and have your class compile and run.
The count method must use recursion, you may not store the number of nodes as an attribute within the class.
You may not use a container from the STL.

I've attached an incomplete BTree.h header file to get you started.

A sample run:

Could be anything that demonstrates the class. A menu-driven program would be great for this.
Perhaps include options for insert, remove, search, count, print operations:

(I)nsert
(R)emove
(S)earch
(C)ount
(P)rint
(Q)uit

Explanation / Answer

#include<iostream.h>

#include<conio.h>

using namespace std;

template<class T>

class BinaryTreeTemplate

private:

{

struct tree_node

{

treenode*left;

treenode*right;

}

treenode*root;

public:

binarysearchtree()

{

void insert(T);

void remove(T);

bool search(T);

void preprint();

int count();

}

if(t->data < parent->data)

{

parent->left = t;

}


else
          
parent->right = t;
  
}

template<class T>

void BinarySearchTree<T>

{

tree_node*t=new tree_node;

t->left=null;

t->right=null;

treenode*currentnode;

current=root;

//insertions

//we are using switch cases

switch(ch)

{

case 1:

cout<<“enter the values”;

b.insert();

case 2:

cout<<“enter the data to be removed”;

b.remove();

case 3:

cout<<“enter the searching elements”;

b.search();

case 4:

cout<<“enter the printed data”;

b.print();

case 5:

cout<<“quit”;

b.quit();

return 0;

}

}