33#ifndef __ADS_CursorBinaryTree
34 #define __ADS_CursorBinaryTree
70 static constexpr int NIL = -1;
79 [[nodiscard]]
bool empty(
void )
const;
82 [[nodiscard]]
int root(
void )
const;
86 [[nodiscard]]
int parent(
int n )
const;
90 [[nodiscard]]
int left(
int n )
const;
94 [[nodiscard]]
int right(
int n )
const;
98 [[nodiscard]]
bool isLeaf(
int n )
const;
102 [[nodiscard]]
const T &
read(
int n )
const;
109 [[nodiscard]]
int size(
void )
const;
169 [[nodiscard]] std::vector< int >
preorder(
void )
const;
177 static std::size_t
size(
const auto & o ) {
return( o.f_N.size() ); }
179 static bool occupied(
const auto & o , std::size_t i ) {
180 return( o.f_N[ i ].used );
183 static int read(
const auto & , std::size_t i ) {
return(
int( i ) ); }
187 [[nodiscard]]
auto nodes(
void )
const {
189 return( std::ranges::subrange( It(
this , 0 ) , It(
this , f_N.size() ) ) );
204 const Node & node(
int n )
const;
206 Node & node(
int n );
210 [[nodiscard]]
bool linked(
void )
const;
212 int make(
const T & v ,
int p );
214 void release(
int n );
218 std::vector< Node > f_N;
233#include "ADS/tree/impl/CursorBinaryTree.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...
int setRoot(const T &v)
the root of value of the empty tree
void remove(int n)
removes the subtree of , detached from its parent, its places back to the free list,...
int insertRight(int n, const T &v)
a new right child of of value , which must be missing, as insertLeft() on the right
int insertRight(int n, const CursorBinaryTree &t, int s)
a copy of the subtree of in as the right subtree of , as the insertLeft() above on the right
int insertLeft(int n, const T &v)
a new left child of of value , which must be missing
CursorBinaryTree(const T &v)
a tree of one node of value
T Item
the type of the values
Definition CursorBinaryTree.h:69
int right(int n) const
the right child of , NIL if missing
bool empty(void) const
true if the tree has no node
int root(void) const
the place of the root, NIL if the tree is empty
int left(int n) const
the left child of , NIL if missing
int size(void) const
the number of nodes
std::vector< int > preorder(void) const
the nodes in preorder
const T & read(int n) const
the value of
void write(int n, const T &v)
writes in
int insertLeft(int n, const CursorBinaryTree &t, int s)
a copy of the subtree of in as the left subtree of ; may be this tree, copied as it was before the...
bool isLeaf(int n) const
true if has no child
int parent(int n) const
the parent of , NIL for the root
static constexpr int NIL
no node
Definition CursorBinaryTree.h:70
auto nodes(void) const
the nodes, in the order of their places, bidirectional
Definition CursorBinaryTree.h:187
CursorBinaryTree(void)=default
the empty tree
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
the places in use, for SlotIterator
Definition CursorBinaryTree.h:175
static int read(const auto &, std::size_t i)
the node of the place , the place itself
Definition CursorBinaryTree.h:183
static std::size_t size(const auto &o)
the places
Definition CursorBinaryTree.h:177
static bool occupied(const auto &o, std::size_t i)
whether the place holds a node
Definition CursorBinaryTree.h:179