home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / arrays / generics / maxarray / heaps.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-22  |  1.9 KB  |  76 lines

  1. Unit Heaps;
  2.  
  3. INTERFACE
  4. Uses MGenHeap,SrtFuncs;
  5.  
  6. { All Heaps additionally inherit the following Methods:
  7.  
  8.   (* MaxArray Methods *)
  9.                              Procedure Create;
  10.                              Procedure Destroy;
  11.  
  12.                              Function MaxSize;
  13.                              Function ElemSize;
  14.  
  15.   (* GenericHeap Methods *)
  16.                              Procedure Copy;
  17.                              Procedure Swap (I,J : LongInt);
  18.                              Procedure SiftDown (I,J : LongInt);
  19.                              Procedure BuidHeap;
  20.                              Procedure ChangeSort (NewSort : SortFunc);
  21.                              Procedure Sort;
  22.                              Procedure HeapSort;
  23. }
  24.  
  25. Type
  26.   IntHeap = Object (GenericHeap)
  27.  
  28.                    { Re-Defining these methods re-introduces Types and }
  29.                    { most importantly, Type-Checking to the Generic    }
  30.                    { (typeless) Heap, as well as making the calls more }
  31.                    { "natural" for the actual applications Heaps.      }
  32.  
  33.                    { Follow this pattern when defining your descendant Heaps }
  34.  
  35.  
  36.                    Procedure Init (MaxElements : LongInt);
  37.  
  38.                    Procedure Accept (I : Integer; Index : LongInt);
  39.  
  40.                    Function Retrieve (Index : LongInt) : Integer;
  41.  
  42.                    Procedure SiftUp (I : Integer; Index : LongInt);
  43.             End;
  44. IMPLEMENTATION
  45.  
  46. Procedure IntHeap.Init;
  47. Begin
  48.   GenericHeap.Init (MaxElements,SizeOf(Integer),SortInteger)
  49. End;
  50.  
  51. Procedure IntHeap.Accept;
  52. Var
  53.   J : Integer;
  54. Begin
  55.   J := I;
  56.   GenericHeap.Accept (J,Index,SizeOf(Integer))
  57. End;
  58.  
  59. Function IntHeap.Retrieve;
  60. Var
  61.   J : Integer;
  62. Begin
  63.   GenericHeap.Retrieve (J,Index,SizeOf(Integer));
  64.   Retrieve := J
  65. End;
  66.  
  67. Procedure IntHeap.SiftUp;
  68. Var
  69.   J : Integer;
  70. Begin
  71.   J := I;
  72.   GenericHeap.SiftUp (J,Index,SizeOf(Integer))
  73. End;
  74.  
  75. BEGIN
  76. END.