diff --git a/librerie/exercise4/binarytree/binarytree.cpp b/librerie/exercise4/binarytree/binarytree.cpp index 9216be4..028f727 100755 --- a/librerie/exercise4/binarytree/binarytree.cpp +++ b/librerie/exercise4/binarytree/binarytree.cpp @@ -61,9 +61,13 @@ const Data& BinaryTree::Node::Element() const{ /* ----- end of struct Node ----- */ template -bool BinaryTree::operator==(const BinaryTree& toCompare) const noexcept{ - if(size!=toCompare.size) return false; - return(Root() == toCompare.Root()); +bool BinaryTree::operator==(const BinaryTree& tree) const noexcept{ + if(size == tree.size){ + if(size == 0) return true; + else return (Root() == tree.Root()); + }else{ + return false; + } } template diff --git a/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp b/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp index 5b49da9..eca6ed9 100755 --- a/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp +++ b/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp @@ -140,14 +140,15 @@ BinaryTreeLnk& BinaryTreeLnk::operator=(BinaryTreeLnk&& tree) return *this; } +/* +** operator== and operator!= can be removed from BinaryTreeLnk since they are +** inherited from BinaryTree. They're here just for clarity and because they're +** in the template. +** Maybe you can make them more optimized here. +*/ template bool BinaryTreeLnk::operator==(const BinaryTreeLnk& tree) const noexcept{ - if(size == tree.size){ - if(size == 0) return true; - else return (Root() == tree.Root()); - }else{ - return false; - } + return (BinaryTree::operator==(tree)); } template diff --git a/librerie/exercise4/binarytree/lnk/binarytreelnk.hpp b/librerie/exercise4/binarytree/lnk/binarytreelnk.hpp index 09d5aa2..85c852e 100755 --- a/librerie/exercise4/binarytree/lnk/binarytreelnk.hpp +++ b/librerie/exercise4/binarytree/lnk/binarytreelnk.hpp @@ -15,11 +15,10 @@ protected: protected: using BinaryTree::Node::data; - - public: struct NodeLnk* left = nullptr; struct NodeLnk* right = nullptr; + public: struct NodeLnk& operator=(const NodeLnk&); // Copy assignment of abstract types should not be possible. struct NodeLnk& operator=(NodeLnk&&) noexcept; // Move assignment of abstract types should not be possible. bool IsLeaf() const noexcept override; // (concrete function should not throw exceptions)