Elm
1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
#include <elm/avl/Tree.h>
Classes | |
class | Node |
Public Member Functions | |
virtual | ~Tree (void) |
bool | isEmpty (void) |
int | count (void) |
Node * | get (Node *node) |
bool | contains (Node *node) |
void | visit (Visitor *visitor) |
void | search (Visitor *visitor) |
void | insert (Node *node) |
void | remove (Node *node) |
void | clean (void) |
Public Member Functions inherited from elm::inhstruct::BinTree | |
BinTree (void) | |
bool | isEmpty (void) const |
bool | contains (Node *node) |
int | count (void) const |
Node * | root (void) const |
void | setRoot (Node *node) |
void | visit (Visitor *visitor) const |
void | visitPreOrder (Visitor *visitor) const |
void | visitPostOrder (Visitor *visitor) const |
void | search (Visitor *visitor) const |
void | clear (void) |
Protected Member Functions | |
virtual int | compare (Node *node1, Node *node2)=0 |
virtual void | free (Node *node) |
Implementation of the Adelson-Velskii and Landis (AVL) tree algorithm. In order to use this class, you must make a class inheriting this class and overload the compare() protected method. Nodes inserted in the tree must also inherit from the AVLTree::AVLNode class.
|
virtual |
void elm::avl::Tree::clean | ( | void | ) |
This method is called for comparing nodes. It must be overloaded for getting an actual implementation of AVL tree.
node1 | First node to compare. |
node2 | Second node to compare. |
Referenced by get().
bool elm::avl::Tree::contains | ( | Node * | node | ) |
Test if the given node value is contained in the tree.
int elm::avl::Tree::count | ( | void | ) |
count the number of nodes in the tree.
|
protectedvirtual |
Dump the content of tree. For debugging purpose, only. This method is called for freeing a node in the tree. This method may be overloaded for providing special freeing method. Not overloaded, do nothing.
node | Node to free. |
Tree::Node * elm::avl::Tree::get | ( | Node * | node | ) |
Get a tree node equal to the given one.
node | Node to test for equality. |
References elm::avl::Tree::Node::_left(), elm::avl::Tree::Node::_right(), and compare().
void elm::avl::Tree::insert | ( | Node * | node | ) |
Insert a new node in the tree.
node | Node to insert. |
References elm::inhstruct::BinTree::setRoot().
bool elm::avl::Tree::isEmpty | ( | void | ) |
Test if the tree is empty.
void elm::avl::Tree::remove | ( | Node * | node | ) |
Remove a node from the tree.
node | Node to remove. |
References elm::inhstruct::BinTree::setRoot().
void elm::avl::Tree::search | ( | Visitor * | visitor | ) |
Look for a special node in the given tree.For each node, the process() method of the visitor is called. If it returns 0, search stops. If it returns, <0 traversal continue with left child else with the right child.
visitor | Visitor to use. |
void elm::avl::Tree::visit | ( | Visitor * | visitor | ) |
Visit the node of the tree.
visitor | The method process() of this object is called with each tree node. |