Library 3

This commit is contained in:
Alessandro Ferro 2021-04-26 19:12:17 +02:00
parent 0d599672c4
commit c550ec0ef4
4 changed files with 301 additions and 117 deletions

Binary file not shown.

View File

@ -5,7 +5,185 @@ namespace lasd {
/* ************************************************************************** */ /* ************************************************************************** */
// ... // checks if two trees which have the same root node are identical
template <typename Data>
bool BinaryTree<Data>::Node::operator==(const Node& toEvaluate){
return EqualNodes(this, &toEvaluate);
}
bool BinaryTree<Data>::Node::EqualNodes(Node* n1, Node* n2){
if(n1->IsLeaf() && n2->IsLeaf() && n1->data == n2->data) return true;
if( (n1->HasLeftChild() && !n2->HasLeftChild()) || (n1->HasRightChild() && !n2->HasRightChild()) ) return false;
return( n1->data == n2->data &&
EqualNodes(n1->LeftChild(),n2->LeftChild()) &&
EqualNodes(n1->RightChild(),n2->RightChild())
)
}
template <typename Data>
bool BinaryTree<Data>::Node::operator!=(const Node& toEvaluate){
return !(*this == toEvaluate)
}
template <typename Data>
Data& BinaryTree<Data>::Node::Element(){
return this->data;
}
template <typename Data>
const Data& BinaryTree<Data>::Node::Element(){
return this->data;
}
template <typename Data>
bool BinaryTree<Data>::operator==(const BinaryTree& toCompare) const noexcept{
return(Root() == toCompare.Root());
}
template <typename Data>
bool BinaryTree<Data>::operator!=(const BinaryTree& toCompare) const noexcept{
return(Root() != toCompare.Root());
}
template <typename Data>
void BinaryTree<Data>::MapPreOrder(const MapFunctor function, void* par){
MapPreOrder(function, par, &Root());
}
template <typename Data>
void BinaryTree<Data>::MapPostOrder(const MapFunctor function, void* par){
MapPostOrder(function, par, &Root());
}
template <typename Data>
void BinaryTree<Data>::FoldPreOrder(const FoldFunctor function, const void* par, void* acc){
FoldPreOrder(function, par, acc, &Root());
}
template <typename Data>
void BinaryTree<Data>::FoldPostOrder(const FoldFunctor function, const void* par, void* acc) const{
FoldPostOrder(function, par, acc, &Root());
}
template <typename Data>
void BinaryTree<Data>::MapInOrder(const MapFunctor function, void* par){
MapInOrder(function, par, &Root());
}
template <typename Data>
void BinaryTree<Data>::FoldInOrder(const MapFunctor function, const void* par, void* acc) const{
FoldInOrder(function, par, acc, &Root());
}
template <typename Data>
void BinaryTree<Data>::MapBreadth(const MapFunctor function, void* par){
MapBreadth(function, par, &Root());
}
template <typename Data>
void BinaryTree<Data>::FoldBreadth(const FoldFunctor function, const void* par, void* acc) const{
FoldBreadth(function, par, acc, &Root());
}
/* ----- AUX ----- */
template <typename Data>
void BinaryTree<Data>::MapPreOrder(const MapFunctor function, void* par, Node* node){
if(node != nullptr){
function(node->Element(), par);
if(node->HasLeftChild()){
MapPreOrder(function, par, node->LeftChild());
}
if(node->HasRightChild()){
MapPreOrder(function, par, node->RightChild());
}
}
}
template <typename Data>
void BinaryTree<Data>::MapPostOrder(const MapFunctor function, void* par, Node* node){
if(node != nullptr){
if(node->HasLeftChild()){
MapPreOrder(function, par, node->LeftChild());
}
if(node->HasRightChild()){
MapPreOrder(function, par, node->RightChild());
}
function(node->Element(), par);
}
}
template <typename Data>
void BinaryTree<Data>::FoldPreOrder(const FoldFunctor function, const void* par, void* acc, const Node* node){
if(node != nullptr){
function(node->Element(), par, acc);
if(node->HasLeftChild()){
FoldPreOrder(function, par, acc, node->LeftChild());
}
if(node->HasRightChild()){
FoldPreOrder(function, par, acc, node->RightChild());
}
}
}
template <typename Data>
void BinaryTree<Data>::FoldPostOrder(const FoldFunctor function, const void* par, void* acc, const Node* node){
if(node != nullptr){
if(node->HasLeftChild()){
FoldPreOrder(function, par, acc, node->LeftChild());
}
if(node->HasRightChild()){
MapPreOrder(function, par, acc, node->RightChild());
}
function(node->Element(), par, acc);
}
}
template <typename Data>
void BinaryTree<Data>::MapInOrder(const MapFunctor function, void* par, Node* node){
if(node != nullptr){
if(node->HasLeftChild()){
MapInOrder(function, par, node->LeftChild());
}
function(node->Element(), par);
if(node->HasRightChild()){
MapInOrder(function, par, node->RightChild());
}
}
}
template <typename Data>
void FoldInOrder(const FoldFunctor function, const void* par, void* acc, const Node* node) const{
if(node != nullptr){
if(node->HasLeftChild()){
FoldInOrder(function, par, acc, node->LeftChild());
}
function(node->Element(), par, acc);
if(node->HasRightChild()){
FoldPreOrder(function, par, acc, node->RightChild());
}
}
}
template <typename Data>
void MapBreadth(const MapFunctor function, void* par, Node* node){
QueueLst<struct Node*> toVisit;
if(node != nullptr){
toVisit.Enqueue(node);
while(!toVisit.Empty()){
func(toVisit.Head()->Element(), par);
if(toVisit.Head()->HasLeftChild()){
toVisit.Enqueue(&(toVisit.Head()->LeftChild()));
}
if(toVisit.Head()->HasRightChild()){
toVisit.Enqueue(&(toVisit.Head()->RightChild()));
}
ql.Dequeue();
}
}
}
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -8,7 +8,13 @@
#include "../iterator/iterator.hpp" #include "../iterator/iterator.hpp"
// #include "..." #include "../queue/queue.hpp"
#include "../queue/vec/queuevec.hpp"
#include "../queue/lst/queuelst.hpp"
#include "../stack/stack.hpp"
#include "../stack/lst/stacklst.hpp"
#include "../stack/vec/stackvec.hpp"
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,17 +23,16 @@ namespace lasd {
/* ************************************************************************** */ /* ************************************************************************** */
template <typename Data> template <typename Data>
class BinaryTree { // Must extend InOrder/BreadthMappableContainer<Data> and InOrder/BreadthFoldableContainer<Data> class BinaryTree : virtual public InOrderMappableContainer<Data>,
virtual public BreadthMappableContainer<Data>,
virtual public InOrderFoldableContainer<Data>,
virtual public BreadthFoldableContainer<Data>{ // Must extend InOrder/BreadthMappableContainer<Data> and InOrder/BreadthFoldableContainer<Data>
private: private:
// ...
protected: protected:
// using InOrder/BreadthMappableContainer<Data>::???; using BreadthMappableContainer<Data>::size;
// ...
public: public:
@ -35,399 +40,392 @@ public:
private: private:
// ...
protected: protected:
Data data;
// Comparison operators
bool operator==(const Node&) const noexcept; // Comparison of abstract types is possible, but should not be visible.
bool operator!=(const Node&) const noexcept; // Comparison of abstract types is possible, but should not be visible.
bool EqualNodes(Node*, Node*);
// ...
public: public:
// friend class BinaryTree<Data>; friend class BinaryTree<Data>;
/* ********************************************************************** */ /* ********************************************************************** */
// Destructor // Destructor
// ~Node() specifiers virtual ~Node() = default;
/* ********************************************************************** */ /* ********************************************************************** */
// Copy assignment // Copy assignment
// type operator=(argument); // Copy assignment of abstract types should not be possible. Node& operator=(const Node&) = delete; // Copy assignment of abstract types should not be possible.
// Move assignment // Move assignment
// type operator=(argument); // Move assignment of abstract types should not be possible. Node& operator=(Node&&) noexcept = delete; // Move assignment of abstract types should not be possible.
/* ********************************************************************** */ /* ********************************************************************** */
// Comparison operators
// type operator==(argument) specifiers; // Comparison of abstract types is possible, but should not be visible.
// type operator!=(argument) specifiers; // Comparison of abstract types is possible, but should not be visible.
/* ********************************************************************** */ /* ********************************************************************** */
// Specific member functions // Specific member functions
// type Element() specifiers; // Mutable access to the element (concrete function should not throw exceptions) Data& Element(); // Mutable access to the element (concrete function should not throw exceptions)
// type Element() specifiers; // Immutable access to the element (concrete function should not throw exceptions) const Data& Element() const; // Immutable access to the element (concrete function should not throw exceptions)
// type IsLeaf() specifiers; // (concrete function should not throw exceptions) virtual bool IsLeaf() const noexcept = 0; // (concrete function should not throw exceptions)
// type HasLeftChild() specifiers; // (concrete function should not throw exceptions) virtual bool HasLeftChild() const noexcept = 0; // (concrete function should not throw exceptions)
// type HasRightChild() specifiers; // (concrete function should not throw exceptions) virtual bool HasRightChild() const noexcept = 0; // (concrete function should not throw exceptions)
// type LeftChild() specifiers; // (concrete function must throw std::out_of_range when not existent) virtual Node& LeftChild() const = 0; // (concrete function must throw std::out_of_range when not existent)
// type RightChild() specifiers; // (concrete function must throw std::out_of_range when not existent) virtual Node& RightChild() const = 0; // (concrete function must throw std::out_of_range when not existent)
}; };
/* ************************************************************************ */ /* ************************************************************************ */
// Destructor // Destructor
// ~BinaryTree() specifiers virtual ~BinaryTree() = default;
/* ************************************************************************ */ /* ************************************************************************ */
// Copy assignment // Copy assignment
// type operator=(argument); // Copy assignment of abstract types should not be possible. BinaryTree& operator=(const BinaryTree&) = delete; // Copy assignment of abstract types should not be possible.
// Move assignment // Move assignment
// type operator=(argument); // Move assignment of abstract types should not be possible. BinaryTree& operator=(BinaryTree&&) noexcept = delete; // Move assignment of abstract types should not be possible.
/* ************************************************************************ */ /* ************************************************************************ */
// Comparison operators // Comparison operators
// type operator==(argument) specifiers; // Comparison of abstract binary tree is possible. bool operator==(const BinaryTree&) const noexcept; // Comparison of abstract binary tree is possible.
// type operator!=(argument) specifiers; // Comparison of abstract binary tree is possible. bool operator!=(const BinaryTree&) const noexcept; // Comparison of abstract binary tree is possible.
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions // Specific member functions
// type Root() specifiers; // (concrete function must throw std::length_error when empty) virtual Node& Root() const = 0; // (concrete function must throw std::length_error when empty)
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from MappableContainer) // Specific member functions (inherited from MappableContainer)
// using typename MappableContainer<Data>::MapFunctor; using typename MappableContainer<Data>::MapFunctor;
// type MapPreOrder(arguments) specifiers; // Override MappableContainer member void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
// type MapPostOrder(arguments) specifiers; // Override MappableContainer member void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from FoldableContainer) // Specific member functions (inherited from FoldableContainer)
// using typename FoldableContainer<Data>::FoldFunctor; using typename FoldableContainer<Data>::FoldFunctor;
// type FoldPreOrder(arguments) specifiers; // Override FoldableContainer member void FoldPreOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
// type FoldPostOrder(arguments) specifiers; // Override FoldableContainer member void FoldPostOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from InOrderMappableContainer) // Specific member functions (inherited from InOrderMappableContainer)
// type MapInOrder(arguments) specifiers; // Override InOrderMappableContainer member void MapInOrder(const MapFunctor, void*) override; // Override InOrderMappableContainer member
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from InOrderFoldableContainer) // Specific member functions (inherited from InOrderFoldableContainer)
// type FoldInOrder(arguments) specifiers; // Override InOrderFoldableContainer member void FoldInOrder(const FoldFunctor, const void*, void*) const override; // Override InOrderFoldableContainer member
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from BreadthMappableContainer) // Specific member functions (inherited from BreadthMappableContainer)
// type MapBreadth(arguments) specifiers; // Override BreadthMappableContainer member MapBreadth(const MapFunctor, void*) override; // Override BreadthMappableContainer member
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from BreadthFoldableContainer) // Specific member functions (inherited from BreadthFoldableContainer)
// type FoldBreadth(arguments) specifiers; // Override BreadthFoldableContainer member void FoldBreadth(const FoldFunctor, const void*, void*) const override; // Override BreadthFoldableContainer member
protected: protected:
// Auxiliary member functions (for MappableContainer) // Auxiliary member functions (for MappableContainer)
// type MapPreOrder(arguments) specifiers; // Accessory function executing from one node of the tree void MapPreOrder(const MapFunctor, void*, Node*) override; // Accessory function executing from one node of the tree
// type MapPostOrder(arguments) specifiers; // Accessory function executing from one node of the tree void MapPostOrder(const MapFunctor, void*, Node*) override; // Accessory function executing from one node of the tree
/* ************************************************************************ */ /* ************************************************************************ */
// Auxiliary member functions (for FoldableContainer) // Auxiliary member functions (for FoldableContainer)
// type FoldPreOrder(arguments) specifiers; // Accessory function executing from one node of the tree void FoldPreOrder(const FoldFunctor, const void*, void*, const Node*) const override; // Accessory function executing from one node of the tree
// type FoldPostOrder(arguments) specifiers; // Accessory function executing from one node of the tree void FoldPostOrder(const FoldFunctor, const void*, void*, const Node*) const override; // Accessory function executing from one node of the tree
/* ************************************************************************ */ /* ************************************************************************ */
// Auxiliary member functions (for InOrderMappableContainer) // Auxiliary member functions (for InOrderMappableContainer)
// type MapInOrder(arguments) specifiers; // Accessory function executing from one node of the tree void MapInOrder(const MapFunctor, void*, Node*) override; // Accessory function executing from one node of the tree
/* ************************************************************************ */ /* ************************************************************************ */
// Auxiliary member functions (for InOrderFoldableContainer) // Auxiliary member functions (for InOrderFoldableContainer)
// type FoldInOrder(arguments) specifiers; // Accessory function executing from one node of the tree void FoldInOrder(const FoldFunctor, const void*, void*, const Node*) const override; // Accessory function executing from one node of the tree
/* ************************************************************************ */ /* ************************************************************************ */
// Auxiliary member functions (for BreadthMappableContainer) // Auxiliary member functions (for BreadthMappableContainer)
// type MapBreadth(arguments) specifiers; // Accessory function executing from one node of the tree void MapBreadth(const MapFunctor, void*, Node*) override; // Accessory function executing from one node of the tree
/* ************************************************************************ */ /* ************************************************************************ */
// Auxiliary member functions (for BreadthFoldableContainer) // Auxiliary member functions (for BreadthFoldableContainer)
// type FoldBreadth(arguments) specifiers; // Accessory function executing from one node of the tree void FoldBreadth(const FoldFunctor, const void*, void*, const Node*) const override; // Accessory function executing from one node of the tree
}; };
/* ************************************************************************** */ /* ************************************************************************** */
template <typename Data> template <typename Data>
class BTPreOrderIterator { // Must extend ForwardIterator<Data> class BTPreOrderIterator : virtual public ForwardIterator<Data> { // Must extend ForwardIterator<Data>
private: private:
// ...
protected: protected:
struct BinaryTree<Data>::Node* curr;
// ... StackLst<Data> stack;
public: public:
// Specific constructors // Specific constructors
// BTPreOrderIterator(argument) specifiers; // An iterator over a given binary tree BTPreOrderIterator(const BinaryTree<Data>&); // An iterator over a given binary tree
/* ************************************************************************ */ /* ************************************************************************ */
// Copy constructor // Copy constructor
// BTPreOrderIterator(argument) specifiers; BTPreOrderIterator(const BTPreOrderIterator&);
// Move constructor // Move constructor
// BTPreOrderIterator(argument) specifiers; BTPreOrderIterator(BTPreOrderIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Destructor // Destructor
// ~BTPreOrderIterator() specifiers; virtual ~BTPreOrderIterator();
/* ************************************************************************ */ /* ************************************************************************ */
// Copy assignment // Copy assignment
// type operator=(argument) specifiers; BTPreOrderIterator& operator=(const BTPreOrderIterator&);
// Move assignment // Move assignment
// type operator=(argument) specifiers; BTPreOrderIterator& operator=(BTPreOrderIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Comparison operators // Comparison operators
// type operator==(argument) specifiers; bool operator==(const BTPreOrderIterator&) const noexcept;
// type operator!=(argument) specifiers; bool operator!=(const BTPreOrderIterator&) const noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from Iterator) // Specific member functions (inherited from Iterator)
// type operator*() specifiers; // (throw std::out_of_range when terminated) struct BinaryTree<Data>::Node operator*() const; // (throw std::out_of_range when terminated)
// type Terminated() specifiers; // (should not throw exceptions) bool Terminated() noexcept; // (should not throw exceptions)
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from ForwardIterator) // Specific member functions (inherited from ForwardIterator)
// type operator++() specifiers; // (throw std::out_of_range when terminated) void operator++(); // (throw std::out_of_range when terminated)
}; };
/* ************************************************************************** */ /* ************************************************************************** */
template <typename Data> template <typename Data>
class BTPostOrderIterator { // Must extend ForwardIterator<Data> class BTPostOrderIterator : virtual public ForwardIterator<Data> { // Must extend ForwardIterator<Data>
private: private:
// ...
protected: protected:
struct BinaryTree<Data>::Node* curr;
// ... StackLst<Data> stack;
public: public:
// Specific constructors // Specific constructors
// BTPostOrderIterator(argument) specifiers; // An iterator over a given binary tree BTPostOrderIterator(const BinaryTree<Data>&); // An iterator over a given binary tree
/* ************************************************************************ */ /* ************************************************************************ */
// Copy constructor // Copy constructor
// BTPostOrderIterator(argument) specifiers; BTPostOrderIterator(const BTPostOrderIterator&);
// Move constructor // Move constructor
// BTPostOrderIterator(argument) specifiers; BTPostOrderIterator(BTPostOrderIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Destructor // Destructor
// ~BTPostOrderIterator() specifiers; virtual ~BTPostOrderIterator();
/* ************************************************************************ */ /* ************************************************************************ */
// Copy assignment // Copy assignment
// type operator=(argument) specifiers; BTPostOrderIterator& operator=(const BTPostOrderIterator&);
// Move assignment // Move assignment
// type operator=(argument) specifiers; BTPostOrderIterator& operator=(BTPostOrderIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Comparison operators // Comparison operators
// type operator==(argument) specifiers; bool operator==(const BTPostOrderIterator&) const noexcept;
// type operator!=(argument) specifiers; bool operator!=(const BTPostOrderIterator&) const noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from Iterator) // Specific member functions (inherited from Iterator)
// type operator*() specifiers; // (throw std::out_of_range when terminated) struct BinaryTree<Data>::Node operator*() const; // (throw std::out_of_range when terminated)
// type Terminated() specifiers; // (should not throw exceptions) bool Terminated() noexcept; // (should not throw exceptions)
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from ForwardIterator) // Specific member functions (inherited from ForwardIterator)
// type operator++() specifiers; // (throw std::out_of_range when terminated) void operator++(); // (throw std::out_of_range when terminated)
}; };
/* ************************************************************************** */ /* ************************************************************************** */
template <typename Data> template <typename Data>
class BTInOrderIterator { // Must extend ForwardIterator<Data> class BTInOrderIterator : virtual public ForwardIterator<Data> { // Must extend ForwardIterator<Data>
private: private:
// ...
protected: protected:
struct BinaryTree<Data>::Node* curr;
// ... StackLst<Data> stack;
public: public:
// Specific constructors // Specific constructors
// BTInOrderIterator(argument) specifiers; // An iterator over a given binary tree BTInOrderIterator(const BinaryTree<Data>&); // An iterator over a given binary tree
/* ************************************************************************ */ /* ************************************************************************ */
// Copy constructor // Copy constructor
// BTInOrderIterator(argument) specifiers; BTInOrderIterator(const BTInOrderIterator&);
// Move constructor // Move constructor
// BTInOrderIterator(argument) specifiers; BTInOrderIterator(BTInOrderIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Destructor // Destructor
// ~BTInOrderIterator() specifiers; virtual ~BTInOrderIterator();
/* ************************************************************************ */ /* ************************************************************************ */
// Copy assignment // Copy assignment
// type operator=(argument) specifiers; BTInOrderIterator& operator=(const BTInOrderIterator&);
// Move assignment // Move assignment
// type operator=(argument) specifiers; BTInOrderIterator& operator=(BTInOrderIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Comparison operators // Comparison operators
// type operator==(argument) specifiers; bool operator==(const BTInOrderIterator&) const noexcept;
// type operator!=(argument) specifiers; bool operator!=(const BTInOrderIterator&) const noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from Iterator) // Specific member functions (inherited from Iterator)
// type operator*() specifiers; // (throw std::out_of_range when terminated) struct BinaryTree<Data>::Node operator*() const; // (throw std::out_of_range when terminated)
// type Terminated() specifiers; // (should not throw exceptions) bool Terminated() noexcept; // (should not throw exceptions)
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from ForwardIterator) // Specific member functions (inherited from ForwardIterator)
// type operator++() specifiers; // (throw std::out_of_range when terminated) void operator++(); // (throw std::out_of_range when terminated)
}; };
/* ************************************************************************** */ /* ************************************************************************** */
template <typename Data> template <typename Data>
class BTBreadthIterator { // Must extend ForwardIterator<Data> class BTBreadthIterator : virtual public ForwardIterator<Data>{ // Must extend ForwardIterator<Data>
private: private:
// ...
protected: protected:
// ... struct BinaryTree<Data>::Node* curr;
QueueVec<Data> queue;
public: public:
// Specific constructors // Specific constructors
// BTBreadthIterator(argument) specifiers; // An iterator over a given binary tree BTBreadthIterator(const BinaryTree<Data>&); // An iterator over a given binary tree
/* ************************************************************************ */ /* ************************************************************************ */
// Copy constructor // Copy constructor
// BTBreadthIterator(argument) specifiers; BTBreadthIterator(const BTBreadthIterator&);
// Move constructor // Move constructor
// BTBreadthIterator(argument) specifiers; BTBreadthIterator(BTBreadthIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Destructor // Destructor
// ~BTBreadthIterator() specifiers; virtual ~BTBreadthIterator();
/* ************************************************************************ */ /* ************************************************************************ */
// Copy assignment // Copy assignment
// type operator=(argument) specifiers; BTBreadthIterator& operator=(const BTBreadthIterator&);
// Move assignment // Move assignment
// type operator=(argument) specifiers; BTBreadthIterator& operator=(BTBreadthIterator&&) noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Comparison operators // Comparison operators
// type operator==(argument) specifiers; bool operator==(const BTBreadthIterator&) const noexcept;
// type operator!=(argument) specifiers; bool operator!=(const BTBreadthIterator&) const noexcept;
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from Iterator) // Specific member functions (inherited from Iterator)
// type operator*() specifiers; // (throw std::out_of_range when terminated) struct BinaryTree<Data>::Node operator*() const; // (throw std::out_of_range when terminated)
// type Terminated() specifiers; // (should not throw exceptions) bool Terminated() noexcept; // (should not throw exceptions)
/* ************************************************************************ */ /* ************************************************************************ */
// Specific member functions (inherited from ForwardIterator) // Specific member functions (inherited from ForwardIterator)
// type operator++() specifiers; // (throw std::out_of_range when terminated) void operator++(); // (throw std::out_of_range when terminated)
}; };

View File

@ -1,10 +1,18 @@
namespace lasd { namespace lasd {
/* ************************************************************************** */ template <typename Data>
void AuxFoldExists(const Data& dat, const void* val, void* exists){
if(dat == *((Data*)val)){
*((bool*)exists) = true;
}
}
// ... template <typename Data>
bool FoldableContainer<Data>::Exists(const Data& dat) const noexcept{
/* ************************************************************************** */ bool exists = false;
FoldPreOrder(&AuxFoldExists<Data>, &dat, &exists);
return exists;
}
} }