diff --git a/librerie/exercise3/binarytree/binarytree.cpp b/librerie/exercise3/binarytree/binarytree.cpp index dabdb14..5060d17 100755 --- a/librerie/exercise3/binarytree/binarytree.cpp +++ b/librerie/exercise3/binarytree/binarytree.cpp @@ -6,7 +6,7 @@ #include "../stack/stack.hpp" #include "../stack/lst/stacklst.hpp" #include "../stack/vec/stackvec.hpp" - +#include namespace lasd { /* ************************************************************************** */ @@ -21,11 +21,22 @@ bool BinaryTree::Node::operator==(const Node& toEvaluate) const noexcept{ template bool BinaryTree::Node::EqualNodes(const Node& n1, const Node& n2) const{ if(n1.data == n2.data){ - if(n1.IsLeaf() && n2.IsLeaf()) return true; + if( (n1.HasLeftChild() && !n2.HasLeftChild()) || (n1.HasRightChild() && !n2.HasRightChild()) ) return false; - return( EqualNodes(n1.LeftChild(),n2.LeftChild()) && - EqualNodes(n1.RightChild(),n2.RightChild()) - ); + + if(n1.HasLeftChild() && n1.HasRightChild()){ + return( EqualNodes(n1.LeftChild(),n2.LeftChild()) && EqualNodes(n1.RightChild(),n2.RightChild())); + } + else if(n1.HasLeftChild() && !n1.HasRightChild()){ + return( EqualNodes(n1.LeftChild(),n2.LeftChild())); + } + else if(!n1.HasLeftChild() && n1.HasRightChild()){ + return( EqualNodes(n1.RightChild(),n2.RightChild())); + } + else if(n1.IsLeaf()) { + return true; + } + }else{ return false; } @@ -48,6 +59,7 @@ const Data& BinaryTree::Node::Element() const{ template bool BinaryTree::operator==(const BinaryTree& toCompare) const noexcept{ + if(size!=toCompare.size) return false; return(Root() == toCompare.Root()); } diff --git a/librerie/exercise3/binarytree/vec/binarytreevec.cpp b/librerie/exercise3/binarytree/vec/binarytreevec.cpp index 53a6ff2..dfb5a35 100755 --- a/librerie/exercise3/binarytree/vec/binarytreevec.cpp +++ b/librerie/exercise3/binarytree/vec/binarytreevec.cpp @@ -32,7 +32,7 @@ bool BinaryTreeVec::NodeVec::IsLeaf() const noexcept{ template bool BinaryTreeVec::NodeVec::HasLeftChild() const noexcept{ - if(index*2+1 < ReferenceToTree->size){ + if( (index*2)+1 < ReferenceToTree->size){ return true; }else{ return false; @@ -41,7 +41,7 @@ bool BinaryTreeVec::NodeVec::HasLeftChild() const noexcept{ template bool BinaryTreeVec::NodeVec::HasRightChild() const noexcept{ - if(index*2+2 < ReferenceToTree->size){ + if((index*2)+2 < ReferenceToTree->size){ return true; }else{ return false; diff --git a/librerie/exercise3/build.sh b/librerie/exercise3/build.sh index bd9c16e..f4b1d27 100755 --- a/librerie/exercise3/build.sh +++ b/librerie/exercise3/build.sh @@ -1,7 +1,7 @@ #! /bin/bash -g++ -O3 -o main \ +g++ -g -o main \ zlasdtest/exercise1/simpletest.cpp zlasdtest/exercise1/fulltest.cpp \ zlasdtest/exercise2/simpletest.cpp zlasdtest/exercise2/fulltest.cpp \ zlasdtest/exercise3/simpletest.cpp zlasdtest/exercise3/fulltest.cpp \ diff --git a/librerie/exercise3/main.cpp b/librerie/exercise3/main.cpp index 34faa12..0c107e9 100755 --- a/librerie/exercise3/main.cpp +++ b/librerie/exercise3/main.cpp @@ -11,6 +11,7 @@ int main() { std::cout << "Lasd Libraries 2020" << std::endl; + //menu(); lasdtest(); // To call in the menu of your library test! return 0; } diff --git a/librerie/exercise3/zlasdtest/test.cpp b/librerie/exercise3/zlasdtest/test.cpp index 49ed51f..92d6ae3 100755 --- a/librerie/exercise3/zlasdtest/test.cpp +++ b/librerie/exercise3/zlasdtest/test.cpp @@ -15,10 +15,10 @@ using namespace std; void lasdtest() { cout << endl << "~*~#~*~ Welcome to the LASD Test Suite ~*~#~*~ " << endl; - testSimpleExercise1(); - testFullExercise1(); - testSimpleExercise2(); - testFullExercise2(); + //testSimpleExercise1(); + //testFullExercise1(); + //testSimpleExercise2(); + //testFullExercise2(); testSimpleExercise3(); testFullExercise3(); cout << endl << "Goodbye!" << endl; diff --git a/librerie/exercise3/zmytest/test.hpp b/librerie/exercise3/zmytest/test.hpp index 99b9987..b42f0b9 100755 --- a/librerie/exercise3/zmytest/test.hpp +++ b/librerie/exercise3/zmytest/test.hpp @@ -2,10 +2,27 @@ #ifndef MYTEST_HPP #define MYTEST_HPP + +#include"../vector/vector.hpp" +#include"../list/list.hpp" +#include"../queue/queue.hpp" +#include"../queue/lst/queuelst.hpp" +#include"../queue/vec/queuevec.hpp" +#include"../stack/stack.hpp" +#include"../stack/lst/stacklst.hpp" +#include"../stack/vec/stackvec.hpp" +#include"../iterator/iterator.hpp" +#include"../binarytree/binarytree.hpp" +#include"../binarytree/lnk/binarytreelnk.hpp" +#include"../binarytree/vec/binarytreevec.hpp" +#include +using namespace std; /* ************************************************************************** */ -// ... +void menu(){ + std::cout<<"MYTESTS\n"; +} + -/* ************************************************************************** */ #endif