DEFINITION MODULE Trees;

(* Copyright (C) 1996 by Marcel Timmermans *)

(* A example of a tree object *)


FROM SYSTEM IMPORT ADDRESS;
FROM Objects IMPORT TObject;

CONST 
  cmpLess=-1;
  cmpEqual=0;
  cmpMore=1;

TYPE
 NodePtr = POINTER TO Node;
 Node = RECORD
          left:NodePtr;
          right:NodePtr;
          data:ADDRESS;
        END;

TTree = CLASS(TObject)
         root:NodePtr;
         PROCEDURE Compare(d:ADDRESS;node:NodePtr):INTEGER;
         PROCEDURE FindComp(d:ADDRESS;node:NodePtr):INTEGER;
         PROCEDURE DoProc(d:ADDRESS);
         PROCEDURE NewItem(d:ADDRESS):NodePtr;
         PROCEDURE Remove(n:NodePtr):ADDRESS;
         PROCEDURE Insert(n:NodePtr;d:ADDRESS):NodePtr;
         PROCEDURE Find(n:NodePtr;d:ADDRESS):NodePtr;
         PROCEDURE Min(tree:NodePtr):NodePtr;
         PROCEDURE FindPred(head:NodePtr; d:ADDRESS; VAR Left:BOOLEAN):NodePtr;
         PROCEDURE Delete(n,del:NodePtr):NodePtr;
         PROCEDURE CountElements():LONGINT; 
         PROCEDURE WalkTree(t:NodePtr);
         PROCEDURE FreeData(d:ADDRESS);
         PROCEDURE DestroyTree(VAR t:NodePtr);
        END;
         

END Trees.
