HELP IN SORTING 10 NUMBERS
Author Message
HELP IN SORTING 10 NUMBERS

Can anyone help me in sorting 10 numbers using the array method?

To be direct:

Program Sort;

Uses Crt;

Type
NumArray = Array [1..10] of Integer; {can be
reals/longint/bytes/doubles/etc}

{ shortest code for sorting stuff.. from small to big }
Procedure Sort (var nums: NumArray);
var
Cnt,Cnt2: Integer;
buf: integer;

begin
for Cnt:=1 to 10 do
for Cnt:=1 to 9 do
if nums[cnt+1]<nums[cnt] then begin
Buf:=Nums[Cnt];
Nums[Cnt]:=Nums[Cnt+1];
Nums[Cnt+1]:=Buf;
end;
end; {procedure}

var
MyVars: NumArray;
Cnt: Integer;

begin
for Cnt:=1 to 10 do MyVars[Cnt]:=Random (200);
Sort (MyVars);
for Cnt:=1 to 10 do WriteLn (MyVars[Cnt]);
end.

Peter Out!

Wed, 18 Jun 1902 08:00:00 GMT
HELP IN SORTING 10 NUMBERS

Quote:

>Peter,
>If I want to sort in seven pass or four pass only?

sorry, this is the only sort I can come up with right now.. vacation is
within a week.. so
my brains won't do a thing.. they're failing me :]

Wed, 18 Jun 1902 08:00:00 GMT
HELP IN SORTING 10 NUMBERS
Hi,

Quote:

> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">

Please!

Quote:
> If I want to sort in seven pass or four pass only?

Open array parameters are the solution. This is a generic example:

procedure PrintArray(a : array of Integer);
var i : Integer;
begin
Writeln('*** Start (', high(a) + 1, ') ***');
for i := 0 to High(a) do Writeln(a[i]);
end;

High(a) determines the index of the last element of the array, and
since the array is zero-based, this is the length - 1.

- Sebastian

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages

Powered by phpBB® Forum Software