Library 3

fixed bug #4 + enhancements
This commit is contained in:
Alessandro Ferro 2021-05-06 19:46:16 +02:00
parent 8e56f33808
commit 5e58c3e7f4
6 changed files with 12 additions and 14 deletions

View File

@ -30,14 +30,12 @@ public:
protected: protected:
Data data; Data data;
// Comparison operators // Comparison operators
bool operator==(const Node&) const noexcept; // Comparison of abstract types is possible, but should not be visible. bool operator==(const Node&) const noexcept; // Comparison of abstract types is possible, but should not be visible.
bool operator!=(const Node&) const noexcept; // Comparison of abstract types is possible, but should not be visible. bool operator!=(const Node&) const noexcept; // Comparison of abstract types is possible, but should not be visible.
bool EqualNodes(const Node&, const Node&) const; bool EqualNodes(const Node&, const Node&) const;
public: public:
friend class BinaryTree<Data>; friend class BinaryTree<Data>;

View File

@ -151,7 +151,7 @@ bool BinaryTreeLnk<Data>::operator!=(const BinaryTreeLnk<Data>& tree) const noex
} }
template <typename Data> template <typename Data>
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::Root() const{ struct BinaryTreeLnk<Data>::NodeLnk& BinaryTreeLnk<Data>::Root() const{
if(size==0) throw std::length_error("Empty tree!"); if(size==0) throw std::length_error("Empty tree!");
return *root; return *root;
} }

View File

@ -10,13 +10,13 @@ class BinaryTreeLnk : virtual public BinaryTree<Data>{ // Must extend BinaryTree
protected: protected:
struct NodeLnk : virtual protected BinaryTree<Data>::Node { // Must extend Node struct NodeLnk : virtual public BinaryTree<Data>::Node { // Must extend Node
protected: protected:
using BinaryTree<Data>::Node::data; using BinaryTree<Data>::Node::data;
struct NodeLnk* left; struct NodeLnk* left = nullptr;
struct NodeLnk* right; struct NodeLnk* right = nullptr;
public: public:
struct NodeLnk& operator=(const NodeLnk&); // Copy assignment of abstract types should not be possible. struct NodeLnk& operator=(const NodeLnk&); // Copy assignment of abstract types should not be possible.
@ -56,7 +56,7 @@ public:
// Specific member functions (inherited from BinaryTree) // Specific member functions (inherited from BinaryTree)
struct BinaryTree<Data>::Node& Root() const override; // Override BinaryTree member (throw std::length_error when empty) NodeLnk& Root() const override; // Override BinaryTree member (throw std::length_error when empty)
// Specific member functions (inherited from Container) // Specific member functions (inherited from Container)

View File

@ -141,7 +141,7 @@ bool BinaryTreeVec<Data>::operator!=(const BinaryTreeVec& bt) const noexcept{
} }
template <typename Data> template <typename Data>
struct BinaryTree<Data>::Node& BinaryTreeVec<Data>::Root() const{ struct BinaryTreeVec<Data>::NodeVec& BinaryTreeVec<Data>::Root() const{
if(size==0) throw std::length_error("Empty tree!"); if(size==0) throw std::length_error("Empty tree!");
return *(tree.Front()); return *(tree.Front());
} }

View File

@ -12,7 +12,7 @@ class BinaryTreeVec : virtual public BinaryTree<Data>{ // Must extend BinaryTree
protected: protected:
struct NodeVec : virtual protected BinaryTree<Data>::Node { // Must extend Node struct NodeVec : virtual public BinaryTree<Data>::Node { // Must extend Node
protected: protected:
using BinaryTree<Data>::Node::data; using BinaryTree<Data>::Node::data;
@ -54,7 +54,7 @@ public:
// Specific member functions (inherited from BinaryTree) // Specific member functions (inherited from BinaryTree)
struct BinaryTree<Data>::Node& Root() const override; // Override BinaryTree member (throw std::length_error when empty) NodeVec& Root() const override; // Override BinaryTree member (throw std::length_error when empty)
// Specific member functions (inherited from Container) // Specific member functions (inherited from Container)

View File

@ -36,8 +36,8 @@ void menu(){
BinaryTreeLnk<string> bt1(vec); BinaryTreeLnk<string> bt1(vec);
BinaryTreeLnk<string> bt2(vec); BinaryTreeLnk<string> bt2(vec);
// if(bt1 == bt2) cout<<"uguali"; if(bt1 == bt2) cout<<"uguali";
else cout<<"NON UGUALI!";
} }