Template Class Tree

Class Documentation

template<class T>
class Tree

an ordered tree, with pointers to parent, first child and next sibling

Public Types

using Item = T

the type of the values

Public Functions

explicit Tree(const T &v)

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

Tree(const Tree&) = delete
Tree &operator=(const Tree&) = delete
~Tree()

destroys the subtrees of the children, 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

Tree *parent(void) const

the parent; nil if the node is a root

Tree *leftmostChild(void) const

the first child; nil if the node is a leaf

Tree *rightSibling(void) const

the next sibling; nil if there is none

void insertChild(Tree *t)

inserts the tree t as the first child of this node, which then owns it

Pre:

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

Post:

t is the first child

void insertSibling(Tree *t)

inserts the tree t as the next sibling of this node, which must not be a root; the parent of this node then owns t

Pre:

t is a root, and this node is not; t is not the root of the tree of this node (which would make a cycle)

Post:

t is the next sibling

bool isLeaf(void) const

true if the node has no child (FOGLIA)

bool isLastSibling(void) const

true if the node has no next sibling (ULTIMOFRATELLO)

void deleteChild(void)

destroys the subtree rooted in the first child

void deleteSibling(void)

destroys the subtree rooted in the next sibling