#include <CNCL/AVLNode.h>
CN_AVLNODE
CNObject
none
CNAVLTree
CNAVLNode
is an abstract base class for nodes of AVL trees.
Derived classes must be implemented for different key types. They must be able to compare their keys between two node and between a node and the serached key of the tree.
Constructors:
CNAVLNode();
CNAVLNode(CNParam *param);
In addition to the member functions required by CNCL, CNAVLNode
provides:
virtual int compare(CNAVLNode*) = 0;
-1
if
the current node's key is lower, 1
of it's higher and 0
if
it's equal to the other node's key.
virtual int find(CNAVLTree*) = 0;
-1
if the current node's key is lower, 1
of it's higher and 0
if it's equal to the searched key.
Derived tree classes must provide a possibility for nodes to get the
currently searched tree key, e.g. as a member variable in the tree
structure.
CNAVLNode *left();
NIL
if
there is no left sub-tree.
CNAVLNode *right();
NIL
if
there is no right sub-tree.
The following example shows parts of a derived class. It
uses simple long
keys to sort and find nodes. See also the
example for CNAVLTree
.
class IntAVLNode : public CNAVLNode { public: /***** Constructors ******************************************/ IntAVLNode(long key): key_(key) {}; public: /***** Public interface **************************************/ virtual int compare(CNAVLNode*); // compare node with another one virtual int find(CNAVLTree*); // compare node with searched key long get_key() { return key_; }; private: /***** Internal private members ******************************/ long key_; // ... }; // ... int IntAVLNode::compare(CNAVLNode *n) { long c = IntAVLNode::cast_from_object(n)->key_; if (key_ < c) return -1; if (key_ > c) return 1; return 0; }; int IntAVLNode::find(CNAVLTree *t) { long c = IntAVLTree::cast_from_object(t)->searchkey; if (key_ < c) return -1; if (key_ > c) return 1; return 0; };
Go to the first, previous, next, last section, table of contents.