a binary tree in a positional vector
More...
#include <ADS/tree/ArrayBinaryTree.h>
|
| using | Item = T |
| | the type of the values
|
|
| | ArrayBinaryTree (void)=default |
| | the empty tree
|
| | ArrayBinaryTree (const T &v) |
| | a tree of one node of value \( v \)
|
| | ArrayBinaryTree (const T &v, const ArrayBinaryTree &l, const ArrayBinaryTree &r) |
| | a new root of value \( v \) with copies of \( l \) and \( r \) as its subtrees
|
| bool | empty (void) const |
| | true if the tree has no node
|
| long | root (void) const |
| | the root, 0, or NIL if the tree is empty
|
| long | parent (long i) const |
| | the parent \( \lfloor ( i - 1 ) / 2 \rfloor \) of \( i \), NIL for the root
|
| long | left (long i) const |
| | the left child \( 2 i + 1 \) of \( i \), NIL if there is none
|
| long | right (long i) const |
| | the right child \( 2 i + 2 \) of \( i \), NIL if there is none
|
| bool | isLeaf (long i) const |
| | true if \( i \) has no child
|
| const T & | read (long i) const |
| | the value of \( i \)
|
| void | write (long i, const T &v) |
| | writes \( v \) in \( i \)
|
| void | setRoot (const T &v) |
| | the root of value \( v \) of the empty tree
|
| void | insertLeft (long i, const ArrayBinaryTree &t) |
| | a copy of \( t \) as the left subtree of \( i \), which must be missing; \( t \) may be this tree, copied as it was before the call
|
| void | insertRight (long i, const ArrayBinaryTree &t) |
| | a copy of \( t \) as the right subtree of \( i \), which must be missing; \( t \) may be this tree, copied as it was before the call: the copy of insertLeft() from \( k = 2 i + 2 \)
|
| void | remove (long i) |
| | empties the subtree of \( i \), a previsit of its places
|
| std::vector< long > | preorder (void) const |
| | the places of the nodes in preorder
|
| auto | nodes (void) const |
| | the nodes, in the order of their places, bidirectional
|
|
| static constexpr long | NIL = -1 |
| | no node
|
template<class T>
class ADS::ArrayBinaryTree< T >
a binary tree in a positional vector
◆ Item
◆ ArrayBinaryTree() [1/3]
◆ ArrayBinaryTree() [2/3]
a tree of one node of value \( v \)
◆ ArrayBinaryTree() [3/3]
template<class T>
| ADS::ArrayBinaryTree< T >::ArrayBinaryTree |
( |
const T & | v, |
|
|
const ArrayBinaryTree< T > & | l, |
|
|
const ArrayBinaryTree< T > & | r ) |
a new root of value \( v \) with copies of \( l \) and \( r \) as its subtrees
◆ empty()
true if the tree has no node
◆ insertLeft()
a copy of \( t \) as the left subtree of \( i \), which must be missing; \( t \) may be this tree, copied as it was before the call
In pseudocode (beyond the book), the place \( j \) of \( t \) copied to the place \( k \), from \( j = 0 \) and \( k = 2 i + 1 \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{copy}( k , t , j ) \cr
2 & \quad \textbf{if}\ t \text{ has no node in } j\ \textbf{then
return} \cr
3 & \quad A[ k ] \gets t.A[ j ]\quad \triangleright\ \text{the vector }
\text{grown to } k \text{ if needed} \cr
4 & \quad \mathrm{copy}( 2 k + 1 , t , 2 j + 1 );\ \mathrm{copy}( 2 k + 2
, t , 2 j + 2 )
\end{array}}
\]
- Precondition
- \( i \) is a node with no left child
◆ insertRight()
a copy of \( t \) as the right subtree of \( i \), which must be missing; \( t \) may be this tree, copied as it was before the call: the copy of insertLeft() from \( k = 2 i + 2 \)
- Precondition
- \( i \) is a node with no right child
◆ isLeaf()
true if \( i \) has no child
- Precondition
- \( i \) is a node
◆ left()
the left child \( 2 i + 1 \) of \( i \), NIL if there is none
- Precondition
- \( i \) is a node
◆ nodes()
the nodes, in the order of their places, bidirectional
◆ parent()
the parent \( \lfloor ( i - 1 ) / 2 \rfloor \) of \( i \), NIL for the root
- Precondition
- \( i \) is a node
◆ preorder()
the places of the nodes in preorder
◆ read()
the value of \( i \)
- Precondition
- \( i \) is a node
◆ remove()
empties the subtree of \( i \), a previsit of its places
- Precondition
- \( i \) is a node
◆ right()
the right child \( 2 i + 2 \) of \( i \), NIL if there is none
- Precondition
- \( i \) is a node
◆ root()
the root, 0, or NIL if the tree is empty
◆ setRoot()
the root of value \( v \) of the empty tree
- Precondition
- the tree is empty
◆ write()
writes \( v \) in \( i \)
- Precondition
- \( i \) is a node
◆ NIL
The documentation for this class was generated from the following file: