Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
SORT.PAS
◄Example► ◄Contents► ◄Index► ◄Back►
PROGRAM sort_array;
{ SORT.PAS: Demonstrates sorting array of pointers. }
CONST
size = 4;
TYPE
real_p = ^Real;
real_array_t = ARRAY[1..size] OF Real;
real_ptrs_t = ARRAY[1..size] OF real_p;
CONST
r : real_array_t = (3.333, 1.111, 2.222, 4.444);
VAR
i : Integer;
r_ptr : real_ptrs_t;
PROCEDURE show( ptr_array : real_ptrs_t;
r_array : real_array_t );
VAR
j : Integer;
BEGIN
Write( '-----------------------------' );
Writeln( '-----------------------------' );
FOR j := 1 TO size DO
BEGIN
Write( 'r_ptr[', j, ']^ = ', ptr_array[j]^:4:3 );
Write( ' r_ptr[', j, '] = ', LongInt(ptr_array[j]) );
Writeln( ' r[', j, '] = ', r_array[j]:4:3 );
END;
END; { procedure show }
PROCEDURE sort( VAR ptr_array : real_ptrs_t );
VAR
x, x1 : Integer;
temp : real_p;
BEGIN
FOR x := 1 TO size DO
FOR x1 := (x + 1) TO (size - 1) DO
IF ptr_array[x]^ > ptr_array[x1]^ THEN
BEGIN
temp := ptr_array[x1];
ptr_array[x1] := ptr_array[x];
ptr_array[x] := temp;
END; { IF clause and FOR statements }
END; { procedure sort }
BEGIN
{ Set up array of pointers. }
FOR i := 1 TO size DO
r_ptr[i] := @r[i];
show( r_ptr, r );
sort( r_ptr );
show( r_ptr, r );
END.