#include <CNCL/AVLTree.h>
CN_CNAVLTREE
CNObject
none
CNAVLNode
CNAVLTree
is realizing a generic AVL tree. It contains nodes
derived from CNAVLNode
and organizes them in a balanced binary search
tree. Such Nodes can be added to the tree, searched for and be removed.
CNAVLTree
is an abstract base class. It provides the general
algorithms needed for AVL trees, but it makes no assumptions on what
kind of key the nodes will be sorted by. Usable AVL trees require
derived classes that specify the key that will be used.
Constructors:
CNAVLTree();
CNAVLTree(CNParam *param);
Destructor:
~CNAVLTree();
CNAVLNode
nodes still in the tree.
In addition to the member functions required by CNCL, CNAVLTree
provides:
bool add(CNAVLNode*);
FALSE
is returned. otherwise
TRUE
is returned.
CNAVLNode *find();
CNAVLTree
. The subclasses have to provide
new find()
functions that manage the key to search for.
Returns a pointer to the found CNAVLNode
on success and
NIL
on failure (key not found).
CNAVLNode *remove();
find()
, but the returned node is also removed from the
tree.
bool empty();
TRUE
if the tree is empty.
void delete_all();
CNAVLNode *find_first();
NIL
if the tree is empty.
CNAVLNode *remove_first();
find_first()
, but also removes the returned node.
CNAVLNode *get_root();
NIL
is the tree is empty.
unsigned long length() const;
The following example shows parts of a derived class. It
uses simple long
keys to sort and find nodes. See also the
example for CNAVLNode
.
class IntAVLTree : public CNAVLTree { friend class IntAVLNode; // ... public: /***** Public interface **************************************/ virtual CNAVLNode *find(long key); virtual CNAVLNode *remove(long key); private: /***** Internal private members ******************************/ long searchkey; // ... }; // ... CNAVLNode *IntAVLTree::find(long key) { searchkey = key; return CNAVLTree::find(); }; CNAVLNode *IntAVLTree::remove(long key) { searchkey = key; return CNAVLTree::remove(); };
Go to the first, previous, next, last section, table of contents.