Library 3

fixed memory leak issues + optimization
This commit is contained in:
Alessandro Ferro 2021-05-08 01:08:12 +02:00
parent c32e658308
commit 2e4f7c3de8
3 changed files with 11 additions and 5 deletions

View File

@ -142,7 +142,11 @@ BinaryTreeLnk<Data>& BinaryTreeLnk<Data>::operator=(BinaryTreeLnk<Data>&& tree)
template <typename Data> template <typename Data>
bool BinaryTreeLnk<Data>::operator==(const BinaryTreeLnk<Data>& tree) const noexcept{ bool BinaryTreeLnk<Data>::operator==(const BinaryTreeLnk<Data>& tree) const noexcept{
return (Root() == tree.Root()); if(size == tree.size){
return (Root() == tree.Root());
}else{
return false;
}
} }
template <typename Data> template <typename Data>

View File

@ -105,6 +105,7 @@ BinaryTreeVec<Data>::~BinaryTreeVec(){
template <typename Data> template <typename Data>
BinaryTreeVec<Data>& BinaryTreeVec<Data>::operator=(const BinaryTreeVec<Data>& bt){ BinaryTreeVec<Data>& BinaryTreeVec<Data>::operator=(const BinaryTreeVec<Data>& bt){
Clear();
size = bt.size; size = bt.size;
tree.Resize(size); tree.Resize(size);
for(ulong i=0 ; i<size ; ++i){ for(ulong i=0 ; i<size ; ++i){
@ -116,6 +117,7 @@ BinaryTreeVec<Data>& BinaryTreeVec<Data>::operator=(const BinaryTreeVec<Data>& b
template <typename Data> template <typename Data>
BinaryTreeVec<Data>& BinaryTreeVec<Data>::operator=(BinaryTreeVec<Data>&& bt) noexcept{ BinaryTreeVec<Data>& BinaryTreeVec<Data>::operator=(BinaryTreeVec<Data>&& bt) noexcept{
Clear();
std::swap(size, bt.size); std::swap(size, bt.size);
std::swap(tree, bt.tree); std::swap(tree, bt.tree);
for(ulong i=0 ; i<size ; ++i){ for(ulong i=0 ; i<size ; ++i){

View File

@ -15,10 +15,10 @@ using namespace std;
void lasdtest() { void lasdtest() {
cout << endl << "~*~#~*~ Welcome to the LASD Test Suite ~*~#~*~ " << endl; cout << endl << "~*~#~*~ Welcome to the LASD Test Suite ~*~#~*~ " << endl;
//testSimpleExercise1(); testSimpleExercise1();
//testFullExercise1(); testFullExercise1();
//testSimpleExercise2(); testSimpleExercise2();
//testFullExercise2(); testFullExercise2();
testSimpleExercise3(); testSimpleExercise3();
testFullExercise3(); testFullExercise3();
cout << endl << "Goodbye!" << endl; cout << endl << "Goodbye!" << endl;