Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
SortedBinTree Class Referenceabstract

#include <elm/inhstruct/SortedBinTree.h>

+ Inheritance diagram for 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 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

◆ ~SortedBinTree()

virtual ~SortedBinTree ( void  )
inlinevirtual

Member Function Documentation

◆ clear()

void clear ( void  )
inline

Remove all items from the tree.

References BinTree::clear().

◆ compare()

int 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 SortedBinTree::get().

◆ contains()

bool contains ( Node node)
inline

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.

References SortedBinTree::get().

◆ count()

int count ( void  )
inline

Count the items in the tree.

Returns
Item count.

Count the number of nodes in the tree.

Returns
Node count.

References BinTree::count().

◆ get()

SortedBinTree::Node * 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 SortedBinTree::compare(), BinTree::Node::left(), BinTree::Node::right(), and BinTree::root().

Referenced by SortedBinTree::contains().

◆ insert()

void insert ( Node node)

Add the given node to the tree.

Parameters
nodeNode to add.

References SortedBinTree::isEmpty(), BinTree::root(), and BinTree::setRoot().

◆ isEmpty()

bool isEmpty ( void  )
inline

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 BinTree::isEmpty().

Referenced by SortedBinTree::insert().

◆ remove()

void remove ( Node node)

Remove a node equals to the given one from the tree.

Parameters
nodeNode to remove.

References BinTree::root(), and BinTree::setRoot().

◆ search()

void search ( Visitor visitor)
inline

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.

◆ visit()

void visit ( Visitor visitor)
inline

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: