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
Get step-by-step solutions from verified subject matter experts
