Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
elm::inhstruct::SortedBinTree Class Referenceabstract

#include <elm/inhstruct/SortedBinTree.h>

+ Inheritance diagram for elm::inhstruct::SortedBinTree:

Public Member Functions

virtual ~SortedBinTree (void)
 
bool isEmpty (void)
 
int count (void)
 
Nodeget (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
 
Noderoot (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)
 

Detailed Description

This class provides a sorted binary tree structure absed on inheritance of its content nodes.

Constructor & Destructor Documentation

virtual elm::inhstruct::SortedBinTree::~SortedBinTree ( void  )
virtual

Member Function Documentation

void elm::genstruct::SortedBinTree< T, C >::clear ( void  )

Remove all items from the tree.

References elm::inhstruct::BinTree::clear().

int elm::inhstruct::SortedBinTree::compare ( Node node1,
Node node2 
)
protectedpure virtual

This method must be defined by inherited classes for providing a node comparing policy.

Parameters
node1First node is comparison.
node2Second node in comparison.
Returns
0 for equality, >0 if first node is greater than second one, <0 else.

Referenced by get().

bool elm::inhstruct::SortedBinTree::contains ( Node node)

Test if the tree contains the given value.

Parameters
valueValue to look for.
Returns
True if the value is found, false else.

Test if the tree contains a node equals to the given one.

Parameters
nodeNode to look for.
Returns
True if there is a node equal to the given one.
int elm::inhstruct::SortedBinTree::count ( void  )

Count the items in the tree.

Returns
Item count.

Count the number of nodes in the tree.

Returns
Node count.

References elm::inhstruct::BinTree::count().

SortedBinTree::Node * elm::inhstruct::SortedBinTree::get ( Node node)

Get the item matching the given value.

Parameters
valueValue to look for.
Returns
Matching value in the tree.

Look for the item matching the given value.

Parameters
valueValue to look for.
defDefault value to return if the value is not found.
Returns
Found value or the default value.

Get the node from the tree that is equal to the given one.

Parameters
nodeNode to test for.
Returns
Found node or null.

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.

Parameters
nodeNode 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.

Returns
True if the tree is empty, false else.

Test if the tree is empty.

Returns
True if tree is empty, false else.

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.

Parameters
nodeNode 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.

Parameters
visitorVisitor to use.
void elm::inhstruct::SortedBinTree::visit ( Visitor visitor)

Visit in order the nodes of the tree.

Parameters
visitorVisitor object to call for each node.

The documentation for this class was generated from the following files: