class AvlTree
MyCpp::Referenced
MyCpp::Object
MyCpp::AvlTree

Balanced binary tree (AVL tree).

In general, operators '>' and '==' must be overloaded fot type T. See method descriptions for details.

Data fields
Node *topThe root node of the tree.

Methods
template <class C> Node*
add (C value)
Add a node to the tree.
template <class C> Node*
addFor (C value)
Add a node to the tree without actual node's value assignment.
void
remove (Node *node)
Remove a node from the tree.
void
clear ()
Clear the tree (i.e., delete all nodes from the tree).
template <class C> Node*
lookup (C c)
Find a node with the specified key value by unconditional traversal of the whole tree.
template <class C> Node*
lookupByTraversal (C c)
Find a node with the specified key value by unconditional traversal of the whole tree.
add

Add a node to the tree.

Operator '>' must be overloaded for comparison between types T and C.

The value passed to this method will be assigned to the value field of the Node structure using the appropriate conversion constructor for type T.

template <class C>
Node* add (C value)
value :  The value that will be associated with the new node.
addFor

Add a node to the tree without actual node's value assignment.

Operator '>' must be overloaded for comparison between types T and C.

This method acts just like the add method, except that it does not assign the passed value to the newly created Node structure, and thus the copying/conversion constructor is not called.

This method is useful, if the value of type C is actually the key for this AVL tree, but there is no appropriate conversion constructor for type T.

template <class C>
Node* addFor (C value)
value :  The value that will be associated with the new node.
remove

Remove a node from the tree.

void remove (Node *node)
node :  The node to remove from the tree.
clear

Clear the tree (i.e., delete all nodes from the tree).

void clear ()
lookup

Find a node with the specified key value by unconditional traversal of the whole tree.

Operators '==' and '>' must be overloaded for comparison between types T and C.

If there is no node with the key value requested, then NULL will be returned.

template <class C>
Node* lookup (C c)
c :  The key value of the node to find.
lookupByTraversal

Find a node with the specified key value by unconditional traversal of the whole tree.

This is an ineffective (O(N) complexity) way of searching for a node in the tree.

Operator '==' must be overloaded for comparison between types T and C.

If there is no node with the key value requested, then NULL will be returned.

template <class C>
Node* lookupByTraversal (C c)
c :  The key value of the node to find.