Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
Andeo1812 committed May 8, 2022
1 parent 056f512 commit 1bd028a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
32 changes: 32 additions & 0 deletions VALGRIND_LOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
==2775== Memcheck, a memory error detector
==2775== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2775== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==2775== Command: ./task
==2775== Parent PID: 2219
==2775==
==2775==
==2775== HEAP SUMMARY:
==2775== in use at exit: 240 bytes in 10 blocks
==2775== total heap usage: 17 allocs, 7 frees, 76,144 bytes allocated
==2775==
==2775== 216 bytes in 9 blocks are indirectly lost in loss record 1 of 2
==2775== at 0x4846013: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2775== by 0x1095BE: BinaryTree<long, Less<long> >::Add(long const&) (in /home/andeo/GitHub/Study_C_CPP/task)
==2775== by 0x1092CF: run(std::istream&, std::ostream&) (in /home/andeo/GitHub/Study_C_CPP/task)
==2775== by 0x109366: main (in /home/andeo/GitHub/Study_C_CPP/task)
==2775==
==2775== 240 (24 direct, 216 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2
==2775== at 0x4846013: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2775== by 0x1095BE: BinaryTree<long, Less<long> >::Add(long const&) (in /home/andeo/GitHub/Study_C_CPP/task)
==2775== by 0x1092CF: run(std::istream&, std::ostream&) (in /home/andeo/GitHub/Study_C_CPP/task)
==2775== by 0x109366: main (in /home/andeo/GitHub/Study_C_CPP/task)
==2775==
==2775== LEAK SUMMARY:
==2775== definitely lost: 24 bytes in 1 blocks
==2775== indirectly lost: 216 bytes in 9 blocks
==2775== possibly lost: 0 bytes in 0 blocks
==2775== still reachable: 0 bytes in 0 blocks
==2775== suppressed: 0 bytes in 0 blocks
==2775==
==2775== For lists of detected and suppressed errors, rerun with: -s
==2775== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
28 changes: 27 additions & 1 deletion module_2/2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,35 @@ class BinaryTree {

BinaryTree() : root(nullptr), size(0) {};

~BinaryTree() = default;
~BinaryTree();
};

template<typename T, typename CompareRule>
BinaryTree<T, CompareRule>::~BinaryTree() {
if (IsEmpty()) {
return;
}

std::stack <Node<T> *> s;

s.push(root);

while (!s.empty()) {
Node<T> *tmp = s.top();
s.pop();

if (tmp->right) {
s.push(tmp->right);
}

if (tmp->left) {
s.push(tmp->left);
}

delete tmp;
}
}

template<typename T, typename CompareRule>
bool BinaryTree<T, CompareRule>::IsEmpty() const {
return !size;
Expand Down

0 comments on commit 1bd028a

Please sign in to comment.