Question: C++ Complete the functions for binStree Class //binSTree.h #ifndef BINTREE_H #define BINTREE_H #include Node.h #include using namespace std; template < class T > class binTree

C++

Complete the functions for binStree Class

//binSTree.h

#ifndef BINTREE_H

#define BINTREE_H

#include "Node.h"

#include

using namespace std;

template < class T > class binTree {

//public function versions call the private functions

public:

// default constructor

binTree();

// returns height of BT

unsigned height() const;

// inserts node in BT

virtual void insert(const T&v);

// inorder traversal of BT

void inorder(void(*fn)(T&));

protected:

//Root for tree

Node < T >* root;

private:

// private versions of functions that have access to nodes and root

unsigned height(Node < T >*) const;

void insert(Node < T >*&p, const T&v);

void inorder(Node < T >*p, void(*fn) (T&));

};

//private version of insert

template

void binSTree ::insert(Node < T >*&, const T&) {

if (p == NULL) { p = new Node(v); }

else if (v < p->data) { insert(p->left, v); }

else if (v > p->data) { insert(p->right, v); }

else { return; }

}

#endif

//Node.h

#ifndef H_NODE

#define H_NODE

// definition for class of nodes in bin tree

template < class T > class binTree; // forward declaration

template < class T > class binSTree; // forward declaration

template < class T >

class Node {

friend class binTree < T >; // binTree is friend

friend class binSTree < T >; // binSTree is friend

public:

// default constructor

Node(const T& x = T(), Node < T >* l = 0, Node < T >* r = 0) :

data(x), left(l), right(r) { }

private:

T data; // data component

Node < T > *left, *right; // left and right links

};

#endif

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!