|
| | BinaryTree (const T &v) |
| | a new tree, made of one node containing \( v \) (the Tree( v ) of the book)
|
| | BinaryTree (const BinaryTree &)=delete |
| | no copy, since a tree owns its subtrees [see copy()]
|
| BinaryTree & | operator= (const BinaryTree &)=delete |
| | no copy, since a tree owns its subtrees [see copy()]
|
| | ~BinaryTree () |
| | destroys the two subtrees, i.e., the whole tree, with a stack of its own rather than by recursion
|
| const T & | read (void) const |
| | the value of the node
|
| void | write (const T &v) |
| | writes \( v \) in the node
|
| BinaryTree * | parent (void) const |
| | the parent; nil if the node is a root
|
| BinaryTree * | left (void) const |
| | the left child; nil if there is none
|
| BinaryTree * | right (void) const |
| | the right child; nil if there is none
|
| void | insertLeft (BinaryTree *t) |
| | inserts the tree \( t \) as the left child, which must be missing
|
| void | insertRight (BinaryTree *t) |
| | inserts the tree \( t \) as the right child, which must be missing, as insertLeft() does on the left
|
| void | deleteLeft (void) |
| | destroys the left subtree
|
| void | deleteRight (void) |
| | destroys the right subtree
|
| BinaryTree * | detachLeft (void) |
| | detaches the left subtree without destroying it: it becomes a root, owned by the caller; nil if there is none
|
| BinaryTree * | detachRight (void) |
| | detaches the right subtree without destroying it: it becomes a root, owned by the caller; nil if there is none, as detachLeft() does on the left
|
template<class T>
class ADS::BinaryTree< T >
a binary tree with pointers to the parent and to the two children
detaches the left subtree without destroying it: it becomes a root, owned by the caller; nil if there is none
In pseudocode (beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{detachLeft}() \cr
2 & \quad t \gets \mathit{left};\ \mathit{left} \gets \textbf{nil} \cr
3 & \quad \textbf{if}\ t \ne \textbf{nil}\ \textbf{then}
\ t.\mathit{parent} \gets \textbf{nil} \cr
4 & \quad \textbf{return}\ t
\end{array}}
\]
- Postcondition
- the left child is missing and the result is nil or a root