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  
 
 [ 3 post ] 

 Relevant Pages 

1. HELP IN SORTING 10 NUMBERS

2. Base 10/Base 2 or Base 2/Base 10 conversion

3. Need Help with sorting through numbers in an array

4. I need Borland Office 2.0 disk #10 : Please help

5. ReportSmith 2.5 and Sybase 10 - help

6. sort numbers

7. Sort n Number of Letters n! times

8. Sort n Number of Lett

9. can't read/write dbf fields with 10 decimals

10. more than 10 params with a Tquery

11. Delphi C/S and Sybase Sytem 10

 

 
Powered by phpBB® Forum Software