| The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information.... |
|

| See also: SortArray (Math1), SortIntoArray, InsertIntoArray | |
Example program SORTINTO.PAS |
|
|
The program SORTINTO.PAS shows the application of the procedures SortArray,SortIntoArray, InsertIntoArray on the calculation of the smallest value of a series of numbers. Out of the input numbers the 17 smallest numbers are shown on the screen.
program sortinto;
uses
crt, math1;
const
MaxNum = 17;
var
ra : array[1..MaxNum] of real;
raix : array[1..MaxNum] of integer;
newval : real;
cnt : integer;
index : word;
EndProg : boolean;
procedure DisplayArray;
(*-------------------*)
var
i : integer;
begin
gotoxy (7,1);
write ('sorted Array Index');
for i:=1 to MaxNum do
begin
gotoxy (10,i+1);
write (ra[i]:10:2, ' ',raix[i]:10);
end;
end;
begin
ClrScr;
for cnt:=1 to MaxNum do
begin
ra[cnt] := 1000.0*random;
raix[cnt] := cnt;
end;
SortArray (addr(ra),MaxNum,rnum,true);
DisplayArray;
EndProg := false;
repeat
gotoxy (1,23); DelLine; DelLine;
gotoxy (1,24);
write ('(ABORT: Enter any character)');
gotoxy (1,23);
write ('Enter a number to be sorted into the array: ');
{$I-} read (newval); {$I+}
if IoResult <> 0
then EndProg := True
else begin
index := SortIntoArray (addr(ra),MaxNum,rnum,
addr(newval),true,true);
if index > 0
then begin
inc (cnt);
InsertIntoArray (addr(raix),MaxNum,inum,
addr(cnt),index);
DisplayArray;
end
else begin
gotoxy (1,23); DelLine; DelLine;
write ('Number to large - press <ESC> to continue');
repeat until readkey = #27;
end;
end;
until EndProg;
end.
|
|