Question: A class that implements the ADT binary tree using a dynamic data structure will need to have a destructor and copy constructure using those traversals

A class that implements the ADT binary tree using a dynamic data structure will need to have a destructor and copy constructure using those traversals

Class bnode {

Public:

Bnode () ; data(0),left(nullptr),right(nullptr){};

Bnode(int x);data(x),left(nullptr),right(nullptr){};

Bnode * ctree (); //copy a tree

Void dtree (); //Delete a tree

Int data;

Bnode * left , * right ;

};

Class btree{

Public:

Btree();root(nullptr){}

Btree(const btree actual){

If (actual.root )root = actual.root ctree();

Else root = nullptr;

}

~btree() { if (root) { root dtree(); delete root;}}

...

Private:

Bnode * root;

};

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!