a binary tree on a vector of nodes linked by their places
More...
#include <ADS/tree/CursorBinaryTree.h>
|
| using | Item = T |
| | the type of the values
|
|
| | CursorBinaryTree (void)=default |
| | the empty tree
|
| | CursorBinaryTree (const T &v) |
| | a tree of one node of value \( v \)
|
| 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 | parent (int n) const |
| | the parent of \( n \), NIL for the root
|
| int | left (int n) const |
| | the left child of \( n \), NIL if missing
|
| int | right (int n) const |
| | the right child of \( n \), NIL if missing
|
| bool | isLeaf (int n) const |
| | true if \( n \) has no child
|
| const T & | read (int n) const |
| | the value of \( n \)
|
| void | write (int n, const T &v) |
| | writes \( v \) in \( n \)
|
| int | size (void) const |
| | the number of nodes
|
| int | setRoot (const T &v) |
| | the root of value \( v \) of the empty tree
|
| int | insertLeft (int n, const T &v) |
| | a new left child of \( n \) of value \( v \), which must be missing
|
| int | insertRight (int n, const T &v) |
| | a new right child of \( n \) of value \( v \), which must be missing, as insertLeft() on the right
|
| int | insertLeft (int n, const CursorBinaryTree &t, int s) |
| | a copy of the subtree of \( t \) in \( s \) as the left subtree of \( n \); \( t \) may be this tree, copied as it was before the call
|
| int | insertRight (int n, const CursorBinaryTree &t, int s) |
| | a copy of the subtree of \( t \) in \( s \) as the right subtree of \( n \), as the insertLeft() above on the right
|
| void | remove (int n) |
| | removes the subtree of \( n \), detached from its parent, its places back to the free list, in time linear in its size
|
| std::vector< int > | preorder (void) const |
| | the nodes in preorder
|
| auto | nodes (void) const |
| | the nodes, in the order of their places, bidirectional
|
|
| static constexpr int | NIL = -1 |
| | no node
|
template<class T>
class ADS::CursorBinaryTree< T >
a binary tree on a vector of nodes linked by their places
◆ Item
◆ CursorBinaryTree() [1/2]
◆ CursorBinaryTree() [2/2]
a tree of one node of value \( v \)
◆ empty()
true if the tree has no node
◆ insertLeft() [1/2]
a copy of the subtree of \( t \) in \( s \) as the left subtree of \( n \); \( t \) may be this tree, copied as it was before the call
In pseudocode (section 5.6), a previsit of \( t \) from \( s \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{copy}( t , s , p ) \cr
2 & \quad \textbf{if}\ s = \mathrm{NIL}\ \textbf{then return}
\ \mathrm{NIL} \cr
3 & \quad c \gets \text{a new node under } p \text{, of value }
t.\mathrm{read}( s ) \cr
4 & \quad N[ c ].\mathit{left} \gets \mathrm{copy}( t , t.\mathrm{left}(
s ) , c ) \cr
5 & \quad N[ c ].\mathit{right} \gets \mathrm{copy}( t ,
t.\mathrm{right}( s ) , c );\ \textbf{return}\ c
\end{array}}
\]
- Precondition
- \( n \) is a node with no left child, \( s \) a node of \( t \)
◆ insertLeft() [2/2]
a new left child of \( n \) of value \( v \), which must be missing
In pseudocode (section 5.5, with cursors), \( N \) the vector of the nodes:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insertLeft}( n , v ) \cr
2 & \quad c \gets \text{a free place, or a new one};\ N[ c ] \gets ( v
, n , \mathrm{NIL} , \mathrm{NIL} ) \cr
3 & \quad N[ n ].\mathit{left} \gets c;\ \textbf{return}\ c
\end{array}}
\]
- Precondition
- \( n \) is a node with no left child
◆ insertRight() [1/2]
a copy of the subtree of \( t \) in \( s \) as the right subtree of \( n \), as the insertLeft() above on the right
- Precondition
- \( n \) is a node with no right child, \( s \) a node of \( t \)
◆ insertRight() [2/2]
a new right child of \( n \) of value \( v \), which must be missing, as insertLeft() on the right
- Precondition
- \( n \) is a node with no right child
◆ isLeaf()
true if \( n \) has no child
- Precondition
- \( n \) is a node
◆ left()
the left child of \( n \), NIL if missing
- Precondition
- \( n \) is a node
◆ nodes()
the nodes, in the order of their places, bidirectional
◆ parent()
the parent of \( n \), NIL for the root
- Precondition
- \( n \) is a node
◆ preorder()
◆ read()
the value of \( n \)
- Precondition
- \( n \) is a node
◆ remove()
removes the subtree of \( n \), detached from its parent, its places back to the free list, in time linear in its size
- Precondition
- \( n \) is a node
◆ right()
the right child of \( n \), NIL if missing
- Precondition
- \( n \) is a node
◆ root()
the place of the root, NIL if the tree is empty
◆ setRoot()
the root of value \( v \) of the empty tree
- Precondition
- the tree is empty
◆ size()
◆ write()
writes \( v \) in \( n \)
- Precondition
- \( n \) is a node
◆ NIL
The documentation for this class was generated from the following file: