34#ifndef __ADS_ArrayBinaryTree
35 #define __ADS_ArrayBinaryTree
73 static constexpr long NIL = -1;
87 [[nodiscard]]
bool empty(
void )
const;
90 [[nodiscard]]
long root(
void )
const;
95 [[nodiscard]]
long parent(
long i )
const;
99 [[nodiscard]]
long left(
long i )
const;
103 [[nodiscard]]
long right(
long i )
const;
107 [[nodiscard]]
bool isLeaf(
long i )
const;
111 [[nodiscard]]
const T &
read(
long i )
const;
151 [[nodiscard]] std::vector< long >
preorder(
void )
const;
159 static std::size_t
size(
const auto & o ) {
return( o.f_A.size() ); }
161 static bool occupied(
const auto & o , std::size_t i ) {
162 return( o.f_A[ i ].has_value() );
165 static long read(
const auto & , std::size_t i ) {
return(
long( i ) ); }
169 [[nodiscard]]
auto nodes(
void )
const {
171 return( std::ranges::subrange( It(
this , 0 ) , It(
this , f_A.size() ) ) );
176 [[nodiscard]]
bool has(
long i )
const;
178 std::optional< T > & place(
long i );
180 const std::optional< T > & at(
long i )
const;
182 std::optional< T > & at(
long i );
185 void clear(
long i );
189 [[nodiscard]]
bool rooted(
void )
const;
197 std::vector< std::optional< T > > f_A;
209#include "ADS/tree/impl/ArrayBinaryTree.tpp"
The QUEUE of the book [see ADT.h] realized with a circular vector of places, the place 0 following t...
The binary TREE of the book: an ordered tree where each node has at most two children,...
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...
a binary tree in a positional vector
Definition ArrayBinaryTree.h:68
long root(void) const
the root, 0, or NIL if the tree is empty
void remove(long i)
empties the subtree of , a previsit of its places
T Item
the type of the values
Definition ArrayBinaryTree.h:72
long parent(long i) const
the parent of , NIL for the root
void insertRight(long i, const ArrayBinaryTree &t)
a copy of as the right subtree of , which must be missing; may be this tree, copied as it was befor...
ArrayBinaryTree(void)=default
the empty tree
ArrayBinaryTree(const T &v, const ArrayBinaryTree &l, const ArrayBinaryTree &r)
a new root of value with copies of and as its subtrees
auto nodes(void) const
the nodes, in the order of their places, bidirectional
Definition ArrayBinaryTree.h:169
std::vector< long > preorder(void) const
the places of the nodes in preorder
static constexpr long NIL
no node
Definition ArrayBinaryTree.h:73
const T & read(long i) const
the value of
void insertLeft(long i, const ArrayBinaryTree &t)
a copy of as the left subtree of , which must be missing; may be this tree, copied as it was before...
long right(long i) const
the right child of , NIL if there is none
bool empty(void) const
true if the tree has no node
void setRoot(const T &v)
the root of value of the empty tree
ArrayBinaryTree(const T &v)
a tree of one node of value
long left(long i) const
the left child of , NIL if there is none
bool isLeaf(long i) const
true if has no child
void write(long i, const T &v)
writes in
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
BinaryTree< T > * copy(const BinaryTree< T > *t)
a deep copy of the subtree , nil if is nil; the caller owns it
the places in use, for SlotIterator
Definition ArrayBinaryTree.h:157
static long read(const auto &, std::size_t i)
the node of the place , the place itself
Definition ArrayBinaryTree.h:165
static bool occupied(const auto &o, std::size_t i)
whether the place holds a node
Definition ArrayBinaryTree.h:161
static std::size_t size(const auto &o)
the places
Definition ArrayBinaryTree.h:159