87 explicit Tree(
const T & v );
114 [[nodiscard]]
const T &
read(
void )
const;
178 [[nodiscard]]
bool linked(
void )
const;
181 [[nodiscard]]
const Tree * top(
void )
const;
184 Tree * f_parent =
nullptr;
185 Tree * f_child =
nullptr;
186 Tree * f_sibling =
nullptr;
213template<
class T ,
class Pre ,
class Post >
226template<
class T ,
class F >
239template<
class T ,
class F >
260template<
class T ,
class F >
303template<
class T ,
class F >
383 static constexpr std::nullptr_t
none =
nullptr;
385 static N * next(
const void * , N * n , N * ) {
386 return( n->rightSibling() );
393 static constexpr std::nullptr_t none =
nullptr;
395 static N * next(
const void * , N * n , N * root ) {
396 if( n->leftmostChild() )
397 return( n->leftmostChild() );
398 for( ; n != root ; n = n->parent() )
399 if( n->rightSibling() )
400 return( n->rightSibling() );
413 std::ranges::subrange( It(
nullptr , t->
leftmostChild() , t ) , It() ) );
436 return( std::ranges::subrange( It(
nullptr , t , t ) , It() ) );
447#include "ADS/tree/impl/Tree.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
an ordered tree, with pointers to parent, first child and next sibling
Definition Tree.h:79
void insertSibling(Tree *t)
inserts the tree as the next sibling of this node, which must not be a root; the parent of this node...
Tree * rightSibling(void) const
the next sibling; nil if there is none
Tree * leftmostChild(void) const
the first child; nil if the node is a leaf
void deleteSibling(void)
destroys the subtree rooted in the next sibling, whose next sibling takes its place
void write(const T &v)
writes in the node
void insertChild(Tree *t)
inserts the tree as the first child of this node, which then owns it, in
const T & read(void) const
the value of the node
Tree * parent(void) const
the parent; nil if the node is a root
void deleteChild(void)
destroys the subtree rooted in the first child, whose next sibling becomes the first child
bool isLastSibling(void) const
true if the node has no next sibling
Tree & operator=(const Tree &)=delete
no copy, since a tree owns its subtrees [see copy()]
T Item
the type of the values
Definition Tree.h:83
Tree(const Tree &)=delete
no copy, since a tree owns its subtrees [see copy()]
Tree(const T &v)
a new tree, made of one node containing (the Tree( v ) of the book)
bool isLeaf(void) const
true if the node has no child, i.e., it is a leaf
~Tree()
destroys the subtrees of the children, i.e., the whole tree, with a stack of its own rather than by r...
a forward iterator on the nodes H (pointers or indices) of the owner O, from a first node,...
Definition Iterators.h:1010
@ none
Definition Capabilities.h:553
void dfs(const G &g, int u, std::vector< bool > &visited, Pre &&pre, Edge &&edge, Post &&post)
the visit in depth from , calling pre( u ) in the previsit, edge( u , v ) on each edge and post( u ) ...
void bfs(const G &g, int r, FN &&node, FE &&edge)
the visit in breadth from , calling node( u ) when is examined and edge( u , v ) when is examined
void pre_visit(BinaryTree< T > *t, F &&f)
the previsit of a binary tree, dfs() with f as pre alone
BinaryTree< T > * copy(const BinaryTree< T > *t)
a deep copy of the subtree , nil if is nil; the caller owns it
std::string to_list(const BinaryTree< T > *t)
the parenthesized list of , () if is nil
void in_visit(BinaryTree< T > *t, F &&f)
the invisit (symmetric visit) of a binary tree, dfs() with f as in alone
void post_visit(BinaryTree< T > *t, F &&f)
the postvisit of a binary tree, dfs() with f as post alone
auto preorder(BinaryTree< T > *t)
the nodes of the subtree of in preorder, first, by the links to the parents
Definition BinaryTree.h:457
int maxWeightLevel(Tree< T > *t)
the first level of largest weight, the weight of a level being the sum of the values of its nodes (th...
auto children(Tree< T > *t)
the children of , from the leftmost, as a range
Definition Tree.h:409
Tree< T > * tree_from_list(std::string_view s)
the tree of the parenthesized list , its values read with >>; the caller owns it