DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦053bc81de⟧ TextFile

    Length: 1718 (0x6b6)
    Types: TextFile
    Names: »QSORT.PAS«

Derivation

└─⟦505fbc898⟧ Bits:30002732 Turbo Pascal 5.0 for C-DOS Partner
    └─⟦this⟧ »DEMOS\QSORT.PAS« 

TextFile


æ Copyright (c) 1985, 88 by Borland International, Inc. å

program qsort;
æ$R-,S-å
uses Crt;

æ This program demonstrates the quicksort algorithm, which      å
æ provides an extremely efficient method of sorting arrays in   å
æ memory. The program generates a list of 1000 random numbers   å
æ between 0 and 29999, and then sorts them using the QUICKSORT  å
æ procedure. Finally, the sorted list is output on the screen.  å
æ Note that stack and range checks are turned off (through the  å
æ compiler directive above) to optimize execution speed.        å

const
  max = 1000;

type
  list = arrayÆ1..maxÅ of integer;

var
  data: list;
  i: integer;

æ QUICKSORT sorts elements in the array A with indices between  å
æ LO and HI (both inclusive). Note that the QUICKSORT proce-    å
æ dure provides only an "interface" to the program. The actual  å
æ processing takes place in the SORT procedure, which executes  å
æ itself recursively.                                           å

procedure quicksort(var a: list; Lo,Hi: integer);

procedure sort(l,r: integer);
var
  i,j,x,y: integer;
begin
  i:=l; j:=r; x:=aÆ(l+r) DIV 2Å;
  repeat
    while aÆiÅ<x do i:=i+1;
    while x<aÆjÅ do j:=j-1;
    if i<=j then
    begin
      y:=aÆiÅ; aÆiÅ:=aÆjÅ; aÆjÅ:=y;
      i:=i+1; j:=j-1;
    end;
  until i>j;
  if l<j then sort(l,j);
  if i<r then sort(i,r);
end;

begin æquicksortå;
  sort(Lo,Hi);
end;

begin æqsortå
  Write('Now generating 1000 random numbers...');
  Randomize;
  for i:=1 to max do dataÆiÅ:=Random(30000);
  Writeln;
  Write('Now sorting random numbers...');
  quicksort(data,1,max);
  Writeln;
  for i:=1 to 1000 do Write(dataÆiÅ:8);
end.
«eof»