namespace lasd { template BST::BST(const LinearContainer& lc){ for(ulong i=0 ; i BST::BST(const BST& bst) : BinaryTreeLnk(bst){} template BST::BST(BST&& bst) noexcept : BinaryTreeLnk(std::move(bst)){} template BST::~BST(){ BinaryTreeLnk::Clear(); } template BST& BST::operator=(const BST& bst){ BinaryTreeLnk::operator=(bst); return *this; } template BST& BST::operator=(BST&& bst) noexcept{ BinaryTreeLnk::operator=(std::move(bst)); return *this; } template bool BST::operator==(const BST& bst) const noexcept{ if(size != bst.Size()) return false; BTInOrderIterator itr1(*this); BTInOrderIterator itr2(bst); for(; !itr1.Terminated() ; ++itr1, ++itr2){ if(*itr1 != *itr2) return false; } return true; } template bool BST::operator!=(const BST& bst) const noexcept{ return !(*this = bst) } template void BST::Insert(const Data& data) noexcept{ NodeLnk*& pointer = FindPointerTo(root, data); if(pointer == nullptr){ pointer = CreateNode(data); size++; } } template void BST::Insert(Data&& data) noexcept{ NodeLnk*& pointer = FindPointerTo(root, data); if(pointer == nullptr){ pointer = new NodeLnk(); std::swap(pointer->value, data); size++; } } template void BST::Remove(const Data& data) noexcept{ delete Detach(FindPointerTo(root,data)); } template const Data& BST::Min() const{ if(root == nullptr) throw std::length_error("Empty tree!"); return FindPointerToMin(root)->Element(); } template Data BST::MinNRemove(){ if(root == nullptr) throw std::length_error("Empty tree!"); return DataNDelete(DetachMin(root)); } template void BST::RemoveMin(){ if(root == nullptr) throw std::length_error("Empty tree!"); return DetachMin(root); } template const Data& BST::Max() const{ if(root == nullptr) throw std::length_error("Empty tree!"); return FindPointerToMax(root)->Element(); } template Data BST::MaxNRemove(){ if(root == nullptr) throw std::length_error("Empty tree!"); return DataNDelete(DetachMax(root)); } template void BST::RemoveMax(){ if(root == nullptr) throw std::length_error("Empty tree!"); return DetachMax(root); } template const Data& BST::Predecessor(const Data& data) const{ NodeLnk* const* ptr = FindPointerToPredecessor(root, data) if(ptr!=nullptr){ return (*(*ptr)).Element(); }else{ throw std::length_error("Predecessor not found!"); } } template Data BST::PredecessorNRemove(const Data& data){ NodeLnk** ptr = FindPointerToPredecessor(root,data); if(ptr!=nullptr){ return DataNDelete(Detach(*ptr)); }else{ throw std::length_error("Predecessor not found!"); } } template void BST::RemovePredecessor(const Data& data){ NodeLnk** ptr = FindPointerToPredecessor(root,data); if(ptr!=nullptr){ delete Detach(*ptr); }else{ throw std::length_error("Predecessor not found!"); } } template const Data& BST::Successor(const Data& data) const{ NodeLnk* const* ptr = FindPointerToSuccessor(root, data) if(ptr!=nullptr){ return (*(*ptr)).Element(); }else{ throw std::length_error("Successor not found!"); } } template Data BST::SuccessorNRemove(const Data& data){ NodeLnk** ptr = FindPointerToSuccessor(root,data); if(ptr!=nullptr){ return DataNDelete(Detach(*ptr)); }else{ throw std::length_error("Successor not found!"); } } template void BST::RemoveSuccessor(const Data& data){ NodeLnk** ptr = FindPointerToSuccessor(root,data); if(ptr!=nullptr){ delete Detach(*ptr); }else{ throw std::length_error("Successor not found!"); } } }