Elm
1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
#include <elm/inhstruct/SortedBinTree.h>
Public Member Functions | |
virtual | ~SortedBinTree (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 | clear (void) |
Protected Member Functions | |
virtual int | compare (Node *node1, Node *node2)=0 |
Protected 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) |
This class provides a sorted binary tree structure absed on inheritance of its content nodes.
|
virtual |
void elm::genstruct::SortedBinTree< T, C >::clear | ( | void | ) |
Remove all items from the tree.
References elm::inhstruct::BinTree::clear().
This method must be defined by inherited classes for providing a node comparing policy.
node1 | First node is comparison. |
node2 | Second node in comparison. |
Referenced by get().
bool elm::inhstruct::SortedBinTree::contains | ( | Node * | node | ) |
Test if the tree contains the given value.
value | Value to look for. |
Test if the tree contains a node equals to the given one.
node | Node to look for. |
int elm::inhstruct::SortedBinTree::count | ( | void | ) |
Count the items in the tree.
Count the number of nodes in the tree.
References elm::inhstruct::BinTree::count().
SortedBinTree::Node * elm::inhstruct::SortedBinTree::get | ( | Node * | node | ) |
Get the item matching the given value.
value | Value to look for. |
Look for the item matching the given value.
value | Value to look for. |
def | Default value to return if the value is not found. |
Get the node from the tree that is equal to the given one.
node | Node to test for. |
References compare(), elm::inhstruct::BinTree::Node::left(), elm::inhstruct::BinTree::Node::right(), and elm::inhstruct::BinTree::root().
void elm::inhstruct::SortedBinTree::insert | ( | Node * | node | ) |
Add the given node to the tree.
node | Node to add. |
References isEmpty(), elm::inhstruct::BinTree::root(), and elm::inhstruct::BinTree::setRoot().
bool elm::inhstruct::SortedBinTree::isEmpty | ( | void | ) |
Test if the tree is empty.
Test if the tree is empty.
References elm::inhstruct::BinTree::isEmpty().
Referenced by insert().
void elm::inhstruct::SortedBinTree::remove | ( | Node * | node | ) |
Remove a node equals to the given one from the tree.
node | Node to remove. |
References elm::inhstruct::BinTree::root(), and elm::inhstruct::BinTree::setRoot().
void elm::inhstruct::SortedBinTree::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::inhstruct::SortedBinTree::visit | ( | Visitor * | visitor | ) |
Visit in order the nodes of the tree.
visitor | Visitor object to call for each node. |