Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

=+ a. How does this change affect the incentives for working?

Answered: 1 week ago