Template Class BinaryTree

Class Documentation

template<class T>
class BinaryTree

a binary tree with pointers to the parent and to the two children

Public Types

using Item = T

the type of the values

Public Functions

explicit BinaryTree(const T &v)

Tree( v ): a new tree, made of one node containing v.

BinaryTree(const BinaryTree&) = delete
BinaryTree &operator=(const BinaryTree&) = delete
~BinaryTree()
const T &read(void) const
void write(const T &v)
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

Pre:

t is a root, not this node nor the root of its tree (which would make a cycle), and the left child is missing

Post:

t is the left child

void insertRight(BinaryTree *t)

inserts the tree t as the right child, which must be missing

Pre:

t is a root, not this node nor the root of its tree (which would make a cycle), and the right child is missing

Post:

t is the right child

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

Post:

the left child is missing and the result is nil or a root

BinaryTree *detachRight(void)

detaches the right subtree without destroying it: it becomes a root, owned by the caller; nil if there is none

Post:

the right child is missing and the result is nil or a root