File tree 1 file changed +18
-0
lines changed
operations_on_datastructures
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,9 @@ class BinaryTree {
91
91
return pivot;
92
92
}
93
93
94
+ BinaryTree (const BinaryTree&) = delete ;
95
+ BinaryTree& operator =(const BinaryTree&) = delete ;
96
+
94
97
public:
95
98
/* *
96
99
* @brief Creates a BinaryTree with a root pointing to NULL.
@@ -100,6 +103,21 @@ class BinaryTree {
100
103
* @brief Creates a BinaryTree with a root with an initial value.
101
104
*/
102
105
explicit BinaryTree (int64_t data) { root = new Node (data); }
106
+
107
+ ~BinaryTree () {
108
+ std::vector<Node*> nodes;
109
+ nodes.emplace_back (root);
110
+ while (!nodes.empty ()) {
111
+ const auto cur_node = nodes.back ();
112
+ nodes.pop_back ();
113
+ if (cur_node) {
114
+ nodes.emplace_back (cur_node->left );
115
+ nodes.emplace_back (cur_node->right );
116
+ delete cur_node;
117
+ }
118
+ }
119
+ }
120
+
103
121
/* *
104
122
* @brief Adds a new Node to the Binary Tree
105
123
*/
You can’t perform that action at this time.
0 commit comments