1 answer

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

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

using std::cout;

using std::endl;

template <class T>

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<T>::preprint( Node* r ) const

{

}

#endif


Answers

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

}

}


.

Similar Solved Questions

1 answer
Chapter 16, Problem 16.064 xIncorrect. Determine Vo in the circuit in the figure below. 2 1...
Chapter 16, Problem 16.064 xIncorrect. Determine Vo in the circuit in the figure below. 2 1 2 j2? 2/0 A 2? Enter (a) the amplitude and (b) the phase angle. The phase angle must be in the interval (-180°, 180°] (a) T3.47 (b) TT-23 degrees...
1 answer
Please also include formulas used 2. Two positive charges are located a distance of 0.58 m...
Please also include formulas used 2. Two positive charges are located a distance of 0.58 m apart on the x axis. At the origin, the charge is 5.5 x 104c, and at x-0.58m the charge is 3.3 x 10-c. At what point is the electric field equal to zero...
1 answer
Swifty Mining Company has purchased a tract of mineral land for $1,278,000. It is estimated that...
Swifty Mining Company has purchased a tract of mineral land for $1,278,000. It is estimated that this tract will yield 170,400 tons of ore with sufficient mineral content to make mining and processing profitable. It is further estimated that 8,520 tons of ore will be mined the first and last year an...
1 answer
31
In a certain region the average horizontal component of Earth'smagnetic field is 22 μT, and the average inclination or "dip" is74°. What is the correspondingmagnitude of Earth's magneticfield in microteslas?NumberUnitsμTT·mT/sJ/TµWbWb/m...
1 answer
"Why are more American women dying after childbirth?" Watch video by PBS News Hour "Why are...
"Why are more American women dying after childbirth?" Watch video by PBS News Hour "Why are more American women dying after childbirth?" at https://www.youtube.com/watch?v=K4AzpCITbhE&t=69s Question: 1. Based on the reports from the video, what is/are the reasons rise of maternal...
1 answer
Mark Sexton and Todd Story have been discussing the future of S&S Air. The company has...
Mark Sexton and Todd Story have been discussing the future of S&S Air. The company has been experiencing fast growth, and the two see only clear skies in the company’s future. However, the fast growth can no longer be funded by internal sources, so Mark and Todd have decided the time is ri...
1 answer
10. According to the first law of thermodynamics, the energy of the universe is constant. Does...
10. According to the first law of thermodynamics, the energy of the universe is constant. Does this mean that AE is always equal to zero? a. Yes, AE = 0 at all times, which is why 9 = -W. b. No, AE does not always equal zero, but this is only due to factors like friction and heat. c. NO, AE does not...
1 answer
09, Problem X1 perpendicular to the arm, as the figure indicates The forearm weighs 18 0...
09, Problem X1 perpendicular to the arm, as the figure indicates The forearm weighs 18 0 N and has a center of grevity s indicated. The sale registers 126 & Determne the ntuae of Jl...
1 answer
Case Study 2 unthinkable tragedy
Case Study No. 2: A young man enters pilot training and needs to take a leave of absence of owing to mental health issues, which he describes as “burnout”. Following therapy, he is allowed to return to his studies and completes the course. After graduation he applies for a position with ...
1 answer
The separate condensed balance sheets of Patrick Corporation and its wholly-owned subsidiary, Sean Corporation, are as...
The separate condensed balance sheets of Patrick Corporation and its wholly-owned subsidiary, Sean Corporation, are as follows: BALANCE SHEETS December 31, 2020 Patrick Sean Cash $ 78,000 $ 66,000 Accounts receivable (net) 130,000 38,000 Inventories 88,000 72,000 Plant and equipm...
1 answer
Can you help me with this problem, since I don't know which charges I have to...
can you help me with this problem, since I don't know which charges I have to consider in summing the different contributes of the energy. thanks Question Hydrogen bonding is responsible for many of the unusual properties of water. A simplified A model represents a hydrogen bond as the electros...
1 answer
Consider a plain vanilla fixed for floating interest rate swap with a notional principal of 4,100,000...
Consider a plain vanilla fixed for floating interest rate swap with a notional principal of 4,100,000 and annual payments. Initially the swap was supposed to last for five years and now three years remain. If the initial fixed rate is 0.09, LIBOR is 0.08, and the year three payment was just made (tw...
1 answer
How did the Tet offensive add to the "so-called" credibility gap?
How did the Tet offensive add to the "so-called" credibility gap?...
1 answer
COX Limited is a multinational telecommunications company owned by a Canadian businesswoman. It has numerous long-term...
COX Limited is a multinational telecommunications company owned by a Canadian businesswoman. It has numerous long-term investments in a wide variety of equity instruments. Some investments have to be measured at fair value at each reporting date. In turn, the unrealized gains will be reported in eit...
1 answer
- III Use the following information to answer the question(s) below. Wyatt Oil has 8 million...
- III Use the following information to answer the question(s) below. Wyatt Oil has 8 million shares outstanding and is about to issue 10 million new shares in an IPO. The IPO price has been set at $15 per share, and the underwriting spread is 6%. The IPO is a big success with investors, and the shar...
1 answer
JavaScript Just use javascript, dont include HTML Follow the instructions bellow for a good rate Create...
JavaScript Just use javascript, dont include HTML Follow the instructions bellow for a good rate Create a program that will display the result of three functions: a) sum the elements from the Fibonacci sequence b) divide them by randomly generated number c) calculate factorial from the rounded resul...
1 answer
QuickBooks Online Question: On the Chart of Accounts, why are the category and detail type selections...
QuickBooks Online Question: On the Chart of Accounts, why are the category and detail type selections important? To explain the category and detail types, use 3 accounts – one asset, one liability, and one expense account. Identify the Category Type, Detail Type, Name, Number and financial sta...
1 answer
How do you convert #(x + 1)^2 + (y + 1)^2 =4# into polar form?
How do you convert #(x + 1)^2 + (y + 1)^2 =4# into polar form?...