Library 3

cleaner code
This commit is contained in:
Alessandro Ferro
2021-05-05 22:37:45 +02:00
parent 2b6dcf6700
commit 8e56f33808
8 changed files with 138 additions and 271 deletions

View File

@ -1,30 +1,17 @@
#ifndef BINARYTREELNK_HPP
#define BINARYTREELNK_HPP
/* ************************************************************************** */
#include "../binarytree.hpp"
/* ************************************************************************** */
namespace lasd {
/* ************************************************************************** */
template <typename Data>
class BinaryTreeLnk : virtual public BinaryTree<Data>{ // Must extend BinaryTree<Data>
private:
protected:
using BinaryTree<Data>::size;
struct NodeLnk : virtual protected BinaryTree<Data>::Node { // Must extend Node
private:
protected:
using BinaryTree<Data>::Node::data;
@ -46,64 +33,42 @@ protected:
};
protected:
using BinaryTree<Data>::size;
struct BinaryTreeLnk<Data>::NodeLnk* root = nullptr;
struct BinaryTreeLnk<Data>::NodeLnk* CreateNode(const Data& data);
public:
// Default constructor
BinaryTreeLnk() = default;
/* ************************************************************************ */
// Specific constructors
BinaryTreeLnk(const LinearContainer<Data>&); // A binary tree obtained from a LinearContainer
/* ************************************************************************ */
// Copy constructor
BinaryTreeLnk(const BinaryTreeLnk<Data>&);
// Move constructor
BinaryTreeLnk(BinaryTreeLnk<Data>&&) noexcept;
/* ************************************************************************ */
// Destructor
virtual ~BinaryTreeLnk();
/* ************************************************************************ */
// Copy assignment
BinaryTreeLnk& operator=(const BinaryTreeLnk<Data>&);
// Move assignment
BinaryTreeLnk& operator=(BinaryTreeLnk<Data>&&) noexcept;
/* ************************************************************************ */
// Comparison operators
bool operator==(const BinaryTreeLnk<Data>&) const noexcept;
bool operator!=(const BinaryTreeLnk<Data>&) const noexcept;
/* ************************************************************************ */
// Specific member functions (inherited from BinaryTree)
struct BinaryTree<Data>::Node& Root() const override; // Override BinaryTree member (throw std::length_error when empty)
/* ************************************************************************ */
// Specific member functions (inherited from Container)
void Clear() override; // Override Container member
// Specific functions
struct BinaryTreeLnk<Data>::NodeLnk* CreateTreeFromLinearContainerInBreadth(const LinearContainer<Data>&,ulong);
struct BinaryTreeLnk<Data>::NodeLnk* CopyTree(struct BinaryTreeLnk<Data>::Node*);
void DeleteTree(BinaryTreeLnk<Data>::NodeLnk* node);
};
/* ************************************************************************** */
}
#include "binarytreelnk.cpp"