home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / arrays / generics / maxarray / test.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1989-07-17  |  1.1 KB  |  61 lines

  1. Program TestHeaps;
  2.  
  3. Uses Heaps,Crt;
  4.  
  5. Const
  6.   Num = 200; {I have successfully sorted 250,000 integers on}
  7.              {my humble little 6.44 mhz 8088 based XT-clone.}
  8.              {Time check was 9hrs, 12 minutes.  -- ECW      }
  9.  
  10. Var
  11.   H : IntHeap;
  12.   I : LongInt;
  13.   J : Integer;
  14.  
  15. Begin
  16.   ClrScr;
  17.   Randomize;
  18.  
  19.   WriteLn (MemAvail,' Bytes Available before Initialization.');
  20.  
  21.   H.Create;
  22.   H.Init(Num);
  23.  
  24.   WriteLn (MemAvail,' Bytes Available after Initialization.');
  25.   WriteLn;
  26.   WriteLn ('SORTING ',Num,' INTEGERS.');
  27.  
  28.   For I := 1 to Num do
  29.     Begin
  30.       J := 1 + Random (MaxInt);
  31.       GoToXY (1,5);
  32.       Write ('Sifting Up ',I,'th Element.');
  33.       H.SiftUp (J,I)
  34.     End;
  35.  
  36.   GoToXY (1,6);
  37.   ClrEol;
  38.   Write ('Sorting');
  39.   H.Sort;
  40.   WriteLn;
  41.  
  42.   For I := 1 to Num do WriteLn (H.Retrieve(I),' was the ',I,'th Element');
  43.  
  44.   ReadLn;
  45.  
  46.   ClrScr;
  47.   WriteLn ('Building Heap from Scratch and then Sorting.');
  48.  
  49.   H.BuildHeap;
  50.  
  51.   WriteLn ('Heap Built.  Sorting...');
  52.  
  53.   H.Sort;
  54.  
  55.   For I := 1 to Num do WriteLn (H.Retrieve(I),' was the ',I,'th Element');
  56.  
  57.   H.Destroy;
  58.  
  59.   ReadLn;
  60.  
  61. End.