Library 4

added previous libreries
This commit is contained in:
Alessandro Ferro
2021-05-11 06:52:44 +02:00
parent 25dadb7de6
commit 97407c2a31
23 changed files with 2366 additions and 962 deletions

108
librerie/exercise4/binarytree/vec/binarytreevec.hpp Normal file → Executable file
View File

@ -2,111 +2,73 @@
#ifndef BINARYTREEVEC_HPP
#define BINARYTREEVEC_HPP
/* ************************************************************************** */
#include "../binarytree.hpp"
#include "../../vector/vector.hpp"
/* ************************************************************************** */
namespace lasd {
/* ************************************************************************** */
template <typename Data>
class BinaryTreeVec { // Must extend BinaryTree<Data>
private:
// ...
class BinaryTreeVec : virtual public BinaryTree<Data>{ // Must extend BinaryTree<Data>
protected:
// using BinaryTree<Data>::???;
// ...
struct NodeVec { // Must extend Node
private:
// ...
struct NodeVec : virtual public BinaryTree<Data>::Node { // Must extend Node
protected:
// ...
using BinaryTree<Data>::Node::data;
ulong index;
BinaryTreeVec<Data>* ReferenceToTree = nullptr;
public:
NodeVec(Data&, ulong, BinaryTreeVec<Data>*);
struct NodeVec& operator=(const NodeVec&); // Copy assignment of abstract types should not be possible.
struct NodeVec& operator=(NodeVec&&) noexcept; // 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 NodeVec& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent)
struct NodeVec& RightChild() const override; // (concrete function must throw std::out_of_range when not existent)
// ...
friend class BinaryTreeVec<Data>;
};
protected:
using BinaryTree<Data>::size;
Vector<struct BinaryTreeVec<Data>::NodeVec*> tree;
public:
// Default constructor
// BinaryTreeVec() specifiers;
BinaryTreeVec() = default;
BinaryTreeVec(const LinearContainer<Data>&); // A binary tree obtained from a LinearContainer
BinaryTreeVec(const BinaryTreeVec<Data>&);
BinaryTreeVec(BinaryTreeVec<Data>&&) noexcept;
/* ************************************************************************ */
virtual ~BinaryTreeVec();
// Specific constructors
// BinaryTreeVec(argument) specifiers; // A binary tree obtained from a LinearContainer
BinaryTreeVec& operator=(const BinaryTreeVec<Data>&);
BinaryTreeVec& operator=(BinaryTreeVec<Data>&&) noexcept;
/* ************************************************************************ */
// Copy constructor
// BinaryTreeVec(argument) specifiers;
// Move constructor
// BinaryTreeVec(argument) specifiers;
/* ************************************************************************ */
// Destructor
// ~BinaryTreeVec() specifiers;
/* ************************************************************************ */
// Copy assignment
// type operator=(argument) specifiers;
// Move assignment
// type operator=(argument) specifiers;
/* ************************************************************************ */
// 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)
/* ************************************************************************ */
NodeVec& Root() const 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 ----- */
// Specific member functions (inherited from BreadthMappableContainer)
// type MapBreadth(arguments) specifiers; // Override BreadthMappableContainer member
/* ************************************************************************ */
// Specific member functions (inherited from BreadthFoldableContainer)
// type FoldBreadth(arguments) specifiers; // Override BreadthFoldableContainer member
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;
};
/* ************************************************************************** */
}
#include "binarytreevec.cpp"