mirror of
https://github.com/xfarrow/lasd.git
synced 2025-06-05 21:49:14 +02:00
Library 4
added previous libreries
This commit is contained in:
97
librerie/exercise4/binarytree/lnk/binarytreelnk.hpp
Normal file → Executable file
97
librerie/exercise4/binarytree/lnk/binarytreelnk.hpp
Normal file → Executable file
@@ -1,99 +1,74 @@
|
||||
|
||||
#ifndef BINARYTREELNK_HPP
|
||||
#define BINARYTREELNK_HPP
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../binarytree.hpp"
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
namespace lasd {
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
template <typename Data>
|
||||
class BinaryTreeLnk { // Must extend BinaryTree<Data>
|
||||
|
||||
private:
|
||||
|
||||
// ...
|
||||
class BinaryTreeLnk : virtual public BinaryTree<Data>{ // Must extend BinaryTree<Data>
|
||||
|
||||
protected:
|
||||
|
||||
// using BinaryTree<Data>::???;
|
||||
|
||||
// ...
|
||||
|
||||
struct NodeLnk { // Must extend Node
|
||||
|
||||
private:
|
||||
|
||||
// ...
|
||||
struct NodeLnk : virtual public BinaryTree<Data>::Node { // Must extend Node
|
||||
|
||||
protected:
|
||||
|
||||
// ...
|
||||
using BinaryTree<Data>::Node::data;
|
||||
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)
|
||||
bool HasLeftChild() const noexcept override; // (concrete function should not throw exceptions)
|
||||
bool HasRightChild() const noexcept override; // (concrete function should not throw exceptions)
|
||||
|
||||
// ...
|
||||
struct NodeLnk& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent)
|
||||
struct NodeLnk& RightChild() const override; // (concrete function must throw std::out_of_range when not existent)
|
||||
|
||||
friend class BinaryTreeLnk<Data>;
|
||||
|
||||
};
|
||||
|
||||
protected:
|
||||
using BinaryTree<Data>::size;
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* root = nullptr;
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CreateNode(const Data& data);
|
||||
|
||||
public:
|
||||
|
||||
// Default constructor
|
||||
// BinaryTreeLnk() specifiers;
|
||||
BinaryTreeLnk() = default;
|
||||
BinaryTreeLnk(const LinearContainer<Data>&); // A binary tree obtained from a LinearContainer
|
||||
BinaryTreeLnk(const BinaryTreeLnk<Data>&);
|
||||
BinaryTreeLnk(BinaryTreeLnk<Data>&&) noexcept;
|
||||
|
||||
/* ************************************************************************ */
|
||||
virtual ~BinaryTreeLnk();
|
||||
|
||||
// Specific constructors
|
||||
// BinaryTreeLnk(argument) specifiers; // A binary tree obtained from a LinearContainer
|
||||
BinaryTreeLnk& operator=(const BinaryTreeLnk<Data>&);
|
||||
BinaryTreeLnk& operator=(BinaryTreeLnk<Data>&&) noexcept;
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
// Copy constructor
|
||||
// BinaryTreeLnk(argument) specifiers;
|
||||
|
||||
// Move constructor
|
||||
// BinaryTreeLnk(argument) specifiers;
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
// Destructor
|
||||
// ~BinaryTreeLnk() 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 BinaryTreeLnk<Data>&) const noexcept;
|
||||
bool operator!=(const BinaryTreeLnk<Data>&) const noexcept;
|
||||
|
||||
// Specific member functions (inherited from BinaryTree)
|
||||
|
||||
// type Root() specifiers; // 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)
|
||||
|
||||
// type Clear() specifiers; // Override Container member
|
||||
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"
|
||||
|
Reference in New Issue
Block a user