Question: 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.

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

In C++ pls

// complete these pre-processor directives

#ifndef

#define

#include

using std::cout;

using std::endl;

template

class BTree

{

public:

// constructor

// destructor

// public interface prototypes

void insert( T );

void remove( T );

void preprint() const;

bool search( T value ) const

int count() const

private:

// define and declare the BTree node here

// recursive method prototypes

void preprint( Node* ) const;

};

// method definitions here

template< class T >

void BTree::preprint( Node* r ) const

{

}

#endif

must finish the btree file as well

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!