#ifndef BST_HPP #define BST_HPP /* ************************************************************************** */ #include "../binarytree/lnk/binarytreelnk.hpp" /* ************************************************************************** */ namespace lasd { /* ************************************************************************** */ template class BST : virtual public BinaryTreeLnk { // Must extend BinaryTreeLnk protected: using BinaryTreeLnk::size; using BinaryTreeLnk::root; using typename BinaryTreeLnk::NodeLnk; public: BST() = default; /* ************************************************************************ */ // Specific constructors BST(const LinearContainer&); // A bst obtained from a LinearContainer /* ************************************************************************ */ // Copy constructor BST(const BST&); // Move constructor BST(BST&&) noexcept; /* ************************************************************************ */ // Destructor virtual ~BST(); /* ************************************************************************ */ // Copy assignment BST& operator=(const BST&); // Move assignment BST& operator=(BST&&) noexcept; /* ************************************************************************ */ // Comparison operators bool operator==(const BST&) const noexcept; bool operator!=(const BST&) const noexcept; /* ************************************************************************ */ // Specific member functions void Insert(const Data&) noexcept; // Copy of the value void Insert(Data&&) noexcept; // Move of the value void Remove(const Data&) noexcept; const Data& Min() const; // (concrete function must throw std::length_error when empty) Data MinNRemove(); // (concrete function must throw std::length_error when empty) void RemoveMin(); // (concrete function must throw std::length_error when empty) const Data& Max() const; // (concrete function must throw std::length_error when empty) Data MaxNRemove(); // (concrete function must throw std::length_error when empty) void RemoveMax(); // (concrete function must throw std::length_error when empty) const Data& Predecessor(const Data&) const; // (concrete function must throw std::length_error when empty) Data PredecessorNRemove(const Data&); // (concrete function must throw std::length_error when empty) void RemovePredecessor(const Data&); // (concrete function must throw std::length_error when empty) const Data& Successor(const Data&) const; // (concrete function must throw std::length_error when empty) Data SuccessorNRemove(const Data&); // (concrete function must throw std::length_error when empty) void RemoveSuccessor(const Data&); // (concrete function must throw std::length_error when empty) /* ************************************************************************ */ // Specific member functions (inherited from TestableContainer) bool Exists(const Data&) const noexcept override; // Override TestableContainer member protected: // Auxiliary member functions Data DataNDelete(NodeLnk*); NodeLnk* Detach(NodeLnk*&) noexcept; NodeLnk* DetachMin(NodeLnk*&) noexcept; NodeLnk* DetachMax(NodeLnk*&) noexcept; NodeLnk* SkipOnLeft(NodeLnk*&) noexcept; NodeLnk* SkipOnRight(NodeLnk*&) noexcept; NodeLnk* const& FindPointerToMin(NodeLnk* const&) const noexcept; NodeLnk*& FindPointerToMin(NodeLnk*&) noexcept; NodeLnk* const& FindPointerToMax(NodeLnk* const&) const noexcept; NodeLnk*& FindPointerToMax(NodeLnk*&) noexcept; NodeLnk* const& FindPointerTo(NodeLnk* const&) const noexcept; NodeLnk*& FindPointerTo(NodeLnk*&) noexcept; NodeLnk* const& FindPointerToPredecessor(NodeLnk* const&) const noexcept; NodeLnk*& FindPointerToPredecessor(NodeLnk*&) noexcept; NodeLnk* const& FindPointerToSuccessor(NodeLnk* const&) const noexcept; NodeLnk*& FindPointerToSuccessor(NodeLnk*&) noexcept; }; /* ************************************************************************** */ } #include "bst.cpp" #endif