home *** CD-ROM | disk | FTP | other *** search
- Unit Heaps;
-
- INTERFACE
- Uses MGenHeap,SrtFuncs;
-
- { All Heaps additionally inherit the following Methods:
-
- (* MaxArray Methods *)
- Procedure Create;
- Procedure Destroy;
-
- Function MaxSize;
- Function ElemSize;
-
- (* GenericHeap Methods *)
- Procedure Copy;
- Procedure Swap (I,J : LongInt);
- Procedure SiftDown (I,J : LongInt);
- Procedure BuidHeap;
- Procedure ChangeSort (NewSort : SortFunc);
- Procedure Sort;
- Procedure HeapSort;
- }
-
- Type
- IntHeap = Object (GenericHeap)
-
- { Re-Defining these methods re-introduces Types and }
- { most importantly, Type-Checking to the Generic }
- { (typeless) Heap, as well as making the calls more }
- { "natural" for the actual applications Heaps. }
-
- { Follow this pattern when defining your descendant Heaps }
-
-
- Procedure Init (MaxElements : LongInt);
-
- Procedure Accept (I : Integer; Index : LongInt);
-
- Function Retrieve (Index : LongInt) : Integer;
-
- Procedure SiftUp (I : Integer; Index : LongInt);
- End;
- IMPLEMENTATION
-
- Procedure IntHeap.Init;
- Begin
- GenericHeap.Init (MaxElements,SizeOf(Integer),SortInteger)
- End;
-
- Procedure IntHeap.Accept;
- Var
- J : Integer;
- Begin
- J := I;
- GenericHeap.Accept (J,Index,SizeOf(Integer))
- End;
-
- Function IntHeap.Retrieve;
- Var
- J : Integer;
- Begin
- GenericHeap.Retrieve (J,Index,SizeOf(Integer));
- Retrieve := J
- End;
-
- Procedure IntHeap.SiftUp;
- Var
- J : Integer;
- Begin
- J := I;
- GenericHeap.SiftUp (J,Index,SizeOf(Integer))
- End;
-
- BEGIN
- END.