Professional Documents
Culture Documents
Uses WinCrt;
Var a: VEC;
i, n: Integer;
{*****************************************************
* In-place sorting of a table a[] in ascending order *
* -------------------------------------------------- *
* Inputs: *
* a : Table of n real numbers *
* lo: Starting index (>=0) *
* hi: Ending index (<=n-1), with lo<hi. *
* Output: *
* a : Table sorted in ascending order. *
*****************************************************}
Procedure sort(Var a: VEC; lo, hi: Integer);
Label return;
Var end_lo,k,mid,start_hi: Integer;
T: Double;
Begin
{Partition the list into two lists and sort them recursively}
sort(a, lo, mid);
sort(a, mid + 1, hi);
return: End;
{main program}
BEGIN
n:=16;
writeln;
writeln(' Initial table A:');
for i:=0 to n-1 do
begin
write(a[i]:6:2,' ');
if i=7 then writeln
end;
sort(a,0, n-1);
writeln;
writeln;
writeln(' Sorted table A:');
for i:=0 to n-1 do
begin
write(a[i]:6:2,' ');
if i=7 then writeln
end;
writeln;
readKey;
DoneWinCrt
END.