#ifndef BINARYTREELNK_HPP #define BINARYTREELNK_HPP /* ************************************************************************** */ #include "../binarytree.hpp" /* ************************************************************************** */ namespace lasd { /* ************************************************************************** */ template class BinaryTreeLnk : virtual public BinaryTree{ // Must extend BinaryTree private: protected: using BinaryTree::size; struct NodeLnk : virtual protected BinaryTree::Node { // Must extend Node private: protected: using BinaryTree::Node::data; struct NodeLnk* left; struct NodeLnk* right; 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 BinaryTree::Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent) struct BinaryTree::Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent) friend class BinaryTreeLnk; }; protected: struct BinaryTreeLnk::NodeLnk* root = nullptr; struct BinaryTreeLnk::NodeLnk* CreateNode(const Data& data); public: // Default constructor BinaryTreeLnk() = default; /* ************************************************************************ */ // Specific constructors BinaryTreeLnk(const LinearContainer&); // A binary tree obtained from a LinearContainer /* ************************************************************************ */ // Copy constructor BinaryTreeLnk(const BinaryTreeLnk&); // Move constructor BinaryTreeLnk(BinaryTreeLnk&&) noexcept; /* ************************************************************************ */ // Destructor virtual ~BinaryTreeLnk(); /* ************************************************************************ */ // Copy assignment BinaryTreeLnk& operator=(const BinaryTreeLnk&); // Move assignment BinaryTreeLnk& operator=(BinaryTreeLnk&&) noexcept; /* ************************************************************************ */ // Comparison operators bool operator==(const BinaryTreeLnk&) const noexcept; bool operator!=(const BinaryTreeLnk&) const noexcept; /* ************************************************************************ */ // Specific member functions (inherited from BinaryTree) struct BinaryTree::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 struct BinaryTreeLnk::NodeLnk* CreateTreeFromLinearContainerInBreadth(const LinearContainer&,ulong); struct BinaryTreeLnk::NodeLnk* CopyTree(struct BinaryTreeLnk::Node*); void DeleteTree(BinaryTreeLnk::NodeLnk* node); }; /* ************************************************************************** */ } #include "binarytreelnk.cpp" #endif