|
| | ChildListTree (void)=default |
| | the empty tree
|
| | ChildListTree (const T &v) |
| | a tree of one node of value \( v \)
|
| | ChildListTree (const ChildListTree &o) |
| | a copy of o, whose nodes keep the positions of their cells in the new lists, not in those of o, in \( O( n ) \)
|
| | ChildListTree (ChildListTree &&o) noexcept=default |
| | the nodes of o, with their lists and cells
|
| ChildListTree & | operator= (const ChildListTree &o) |
| | a copy of o, as the copy constructor
|
| ChildListTree & | operator= (ChildListTree &&o) noexcept=default |
| | the nodes of o, with their lists and cells
|
| 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 | leftmostChild (int n) const |
| | the first child of \( n \), the head of its list, NIL for a leaf
|
| int | rightSibling (int n) const |
| | the next sibling of \( n \), the next cell of the list of its parent, NIL if there is none
|
| bool | isLeaf (int n) const |
| | true if \( n \) has no child
|
| bool | isLastSibling (int n) const |
| | whether \( n \) is the last of its siblings
|
| const List< int > & | children (int n) const |
| | the list of the children of \( n \), in their order
|
| 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 | insertChild (int n, const T &v) |
| | a new first child of \( n \) of value \( v \), in \( O( 1 ) \)
|
| int | insertSibling (int n, const T &v) |
| | a new next sibling of \( n \), not the root, of value \( v \), in \( O( 1 ) \): as insertChild() on the list of the parent of \( n \), after the cell of \( n \)
|
| int | insertChildTree (int n, const ChildListTree &t, int s) |
| | a copy of the subtree of \( t \) in \( s \) as the first child of \( n \), in \( O( m ) \) for \( m \) the nodes of the subtree; \( t \) may be this tree, copied as it was before the call
|
| int | insertSiblingTree (int n, const ChildListTree &t, int s) |
| | a copy of the subtree of \( t \) in \( s \) as the next sibling of \( n \), as insertChildTree() after the cell of \( n \); \( t \) may be this tree, copied as it was before the call
|
| void | remove (int n) |
| | removes the subtree of \( n \), detached from its parent in \( O( 1 ) \) by the position of its cell, its places back to the free list
|
| std::vector< int > | previsit (void) const |
| | the nodes in previsit
|
| std::vector< int > | postvisit (void) const |
| | the nodes in postvisit
|
| std::vector< int > | invisit (int i) const |
| | the nodes in invisit with index \( i \), as CursorTree::invisit() on the lists of the children
|
template<class T>
class ADS::ChildListTree< T >
an ordered tree whose nodes keep the list of their children
a new first child of \( n \) of value \( v \), in \( O( 1 ) \)
In pseudocode (Aho, Hopcroft and Ullman, section 3.3), \( N \) the vector of the nodes and \( C_n \) the list of the children of \( n \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insertChild}( n , v ) \cr
2 & \quad c \gets \text{a free place, or a new one, of value } v
\text{ and parent } n \cr
3 & \quad N[ c ].\mathit{where} \gets C_n.\mathrm{insert}(
C_n.\mathrm{head}() , c ) \cr
4 & \quad \textbf{return}\ c
\end{array}}
\]
- Precondition
- \( n \) is a node
a copy of the subtree of \( t \) in \( s \) as the first child of \( n \), in \( O( m ) \) for \( m \) the nodes of the subtree; \( t \) may be this tree, copied as it was before the call
In pseudocode (section 5.3), the copy a previsit, then linked as in insertChild():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{copy}( t , s , p )\quad \triangleright
\ \text{the subtree of } s \text{ in } t \text{, hung under } p \cr
2 & \quad c \gets \text{a new node under } p \text{, of value }
t.\mathrm{read}( s ) \cr
3 & \quad \textbf{foreach}\ \text{child } u \text{ of } s \text{ in } t
\text{, in order}\ \textbf{do} \cr
4 & \qquad x \gets \mathrm{copy}( t , u , c );\ \text{append } x
\text{ to } C_c \text{ and keep its cell in } N[ x ].\mathit{where}
\cr
5 & \quad \textbf{return}\ c
\end{array}}
\]
- Precondition
- \( n \) is a node, \( s \) a node of \( t \)