Library 3

binarytreevec
This commit is contained in:
Alessandro Ferro
2021-05-01 23:58:12 +02:00
parent 27726938dd
commit 10c5148efc
37 changed files with 200 additions and 43 deletions

57
librerie/exercise3/binarytree/vec/binarytreevec.hpp Normal file → Executable file
View File

@ -14,82 +14,89 @@ namespace lasd {
/* ************************************************************************** */
template <typename Data>
class BinaryTreeVec { // Must extend BinaryTree<Data>
class BinaryTreeVec : virtual public BinaryTree<Data>{ // Must extend BinaryTree<Data>
private:
// ...
protected:
// using BinaryTree<Data>::???;
using BinaryTree<Data>::size;
// using BinaryTree<Data>::Node;
Vector<struct NodeVec*> tree;
// ...
struct NodeVec { // Must extend Node
struct NodeVec : virtual protected BinaryTree<Data>::Node { // Must extend Node
private:
// ...
protected:
// ...
using BinaryTree<Data>::Node::data;
ulong index;
BinaryTreeVec<Data>* ReferenceToTree = nullptr;
public:
// ...
struct BinaryTree<Data>::Node& operator=(const NodeVec&) override; // Copy assignment of abstract types should not be possible.
struct BinaryTree<Data>::Node& operator=(NodeVec&&) noexcept override; // Move assignment of abstract types should not be possible.
bool IsLeaf() const noexcept override; // (concrete function should not throw exceptions)
bool HasLeftChild() const noexcept override; // (concrete function should not throw exceptions)
bool HasRightChild() const noexcept override; // (concrete function should not throw exceptions)
struct BinaryTree<Data>::Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent)
struct BinaryTree<Data>::Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent)
};
public:
// Default constructor
// BinaryTreeVec() specifiers;
BinaryTreeVec() = default;
/* ************************************************************************ */
// Specific constructors
// BinaryTreeVec(argument) specifiers; // A binary tree obtained from a LinearContainer
BinaryTreeVec(const LinearContainer<Data>&); // A binary tree obtained from a LinearContainer
/* ************************************************************************ */
// Copy constructor
// BinaryTreeVec(argument) specifiers;
BinaryTreeVec(const BinaryTreeVec<Data>&);
// Move constructor
// BinaryTreeVec(argument) specifiers;
BinaryTreeVec(BinaryTreeVec<Data>&&) noexcept;
/* ************************************************************************ */
// Destructor
// ~BinaryTreeVec() specifiers;
virtual ~BinaryTreeVec();
/* ************************************************************************ */
// Copy assignment
// type operator=(argument) specifiers;
BinaryTreeVec& operator=(const BinaryTreeVec<Data>&);
// Move assignment
// type operator=(argument) specifiers;
BinaryTreeVec& operator=(BinaryTreeVec<Data>&&) noexcept;
/* ************************************************************************ */
// Comparison operators
// type operator==(argument) specifiers;
// type operator!=(argument) specifiers;
bool operator==(const BinaryTreeVec&) const noexcept;
bool operator!=(const BinaryTreeVec&) const noexcept;
/* ************************************************************************ */
// Specific member functions (inherited from BinaryTree)
// type Root() specifiers; // Override BinaryTree member (throw std::length_error when empty)
struct BinaryTreeVec<Data>::NodeVec& Root() override; // Override BinaryTree member (throw std::length_error when empty)
/* ************************************************************************ */
// Specific member functions (inherited from Container)
// type Clear() specifiers; // Override Container member
void Clear() override; // Override Container member
/* ----- override of map and fold in breadth ----- */
using typename BinaryTree<Data>::MapFunctor;
using typename BinaryTree<Data>::FoldFunctor;
void MapBreadth(const MapFunctor, void*) override;
void FoldBreadth(const FoldFunctor, const void*, void*) const override;
};