Class DAvlTree

Inherits from:
Object
Declared in:
DAvlTree.h

Class Hierarchy

    Object
      |
      +---DAvlTree

Class Description

The avl tree collection class implements a number of methods for creating, inserting, searching and removing (elements in) an avl tree. The implementation is inspired by the book "Algorithms & Data structures" by N. Wirth.

Example:
#include <stdio.h>
#include "ofc/DAvlTree.h"

int main(int argc, char *argv[])
{
  DAvlTree *tree = [DAvlTree alloc];
  DText    *key  = [DText    new  ];
  DText    *val;

  [tree init :[DText class]];            // Init tree, key is a DText object

  [key set :"Key1"];                     // Set key1 and create value1 for tree
  val = [DText new]; [val set :"Value1"];

  [tree insert :key :val];

  [key set :"Key2"];                     // Set key1 and create value1 for tree
  val = [DText new]; [val set :"Value2"];

  [tree insert :key :val];               // Create key2 and value2 for tree

  printf("Number of elements:%ld\n", [tree length]);  // Print tree length

  [key set :"Key2"];
                                         // Check key present
  printf("%s is %s present in tree\n", [key cstring], ([tree has :key] ? "" : "not"));

  val = [tree get :key];
  printf("%s has value %s\n", [key cstring], (val != nil ? [val cstring] : "???"));

  [tree free];                           // Free tree and stored objects
  [key  free];

  return 0;
}
Last modified:
19-Jul-2008 (DAvlTree.h)

Instance Variables

private DAvlNode *_root
the root of the avl-tree
private Class _class
the class of the key
private long _count
the number of nodes in the avl tree

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0