From 2e4f7c3de8c6f8c60e523e04217c48997881c05b Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Sat, 8 May 2021 01:08:12 +0200 Subject: [PATCH] Library 3 fixed memory leak issues + optimization --- librerie/exercise3/binarytree/lnk/binarytreelnk.cpp | 6 +++++- librerie/exercise3/binarytree/vec/binarytreevec.cpp | 2 ++ librerie/exercise3/zlasdtest/test.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp b/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp index ce823cc..9a393f9 100755 --- a/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp +++ b/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp @@ -142,7 +142,11 @@ BinaryTreeLnk& BinaryTreeLnk::operator=(BinaryTreeLnk&& tree) template bool BinaryTreeLnk::operator==(const BinaryTreeLnk& tree) const noexcept{ - return (Root() == tree.Root()); + if(size == tree.size){ + return (Root() == tree.Root()); + }else{ + return false; + } } template diff --git a/librerie/exercise3/binarytree/vec/binarytreevec.cpp b/librerie/exercise3/binarytree/vec/binarytreevec.cpp index 89e0c35..ae60260 100755 --- a/librerie/exercise3/binarytree/vec/binarytreevec.cpp +++ b/librerie/exercise3/binarytree/vec/binarytreevec.cpp @@ -105,6 +105,7 @@ BinaryTreeVec::~BinaryTreeVec(){ template BinaryTreeVec& BinaryTreeVec::operator=(const BinaryTreeVec& bt){ + Clear(); size = bt.size; tree.Resize(size); for(ulong i=0 ; i& BinaryTreeVec::operator=(const BinaryTreeVec& b template BinaryTreeVec& BinaryTreeVec::operator=(BinaryTreeVec&& bt) noexcept{ + Clear(); std::swap(size, bt.size); std::swap(tree, bt.tree); for(ulong i=0 ; i