File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
operations_on_datastructures Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,9 @@ class BinaryTree {
9191 return pivot;
9292 }
9393
94+ BinaryTree (const BinaryTree&) = delete ;
95+ BinaryTree& operator =(const BinaryTree&) = delete ;
96+
9497 public:
9598 /* *
9699 * @brief Creates a BinaryTree with a root pointing to NULL.
@@ -100,6 +103,21 @@ class BinaryTree {
100103 * @brief Creates a BinaryTree with a root with an initial value.
101104 */
102105 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+
103121 /* *
104122 * @brief Adds a new Node to the Binary Tree
105123 */
You can’t perform that action at this time.
0 commit comments