comp.lang.ada
 help / color / mirror / Atom feed
* HELP WITH SIMPLE PROGRAM PLEASE
@ 2000-04-17  0:00 ashraf2000
  2000-04-17  0:00 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: ashraf2000 @ 2000-04-17  0:00 UTC (permalink / raw)


HI,

I am a beginner and trying to sort numbers which are read from a file
in random order and needs to be sorted out in numerical order.
e.g 7,10,1,5,.... into 1,2,3,....
Below is some code to read the number from a file and display them.

Please help me sort them out.

THANKS in advance.
ashraf2000@x-stream.co.uk

----------------------------------
NOTE: i'm using ADAGIDE.
The program doesn't takes input from user. Uses a text file to read
data. (run-runoptions-redirectinput ... to be specific)
----------------------------------
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
with Ada.Numerics.Elementary_Functions;
use Ada.Numerics.Elementary_Functions;

procedure digits_sort is

type no_type is array (1..10) of integer;
no:no_type;

   procedure read is
   begin
      for x in no'first..no'last loop
         get(no(x));
         new_line;
         put(no(x),2);
      end loop;
   end read;

   procedure check is
   temp:integer;
   begin
      if no(1)>no(2) then
         temp:=no(1);
         no(1):=no(2);
         no(2):=temp;
      end if;
   end check;

   procedure output is
   begin
   new_line(3);
      for i in 1..10 loop
         put(no(i),2);
         new_line;
      end loop;
   end output;

begin
read;
check;
output;
end digits_sort;


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HELP WITH SIMPLE PROGRAM PLEASE
  2000-04-17  0:00 HELP WITH SIMPLE PROGRAM PLEASE ashraf2000
@ 2000-04-17  0:00 ` Ted Dennison
  2000-04-17  0:00 ` Robert Dewar
  2000-04-18  0:00 ` Sort, was " Alfred Hilscher
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 2000-04-17  0:00 UTC (permalink / raw)


In article <8df1sn$hh4$1@nnrp1.deja.com>,
  ashraf2000@x-stream.co.uk wrote:

> I am a beginner and trying to sort numbers which are read from a file
> Please help me sort them out.

> procedure digits_sort is
...


Is there a specific problem you have with this code you posted?

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HELP WITH SIMPLE PROGRAM PLEASE
  2000-04-17  0:00 HELP WITH SIMPLE PROGRAM PLEASE ashraf2000
  2000-04-17  0:00 ` Ted Dennison
@ 2000-04-17  0:00 ` Robert Dewar
  2000-04-18  0:00 ` Sort, was " Alfred Hilscher
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 2000-04-17  0:00 UTC (permalink / raw)


In article <8df1sn$hh4$1@nnrp1.deja.com>,
  ashraf2000@x-stream.co.uk wrote:
> HI,
>
> I am a beginner and trying to sort numbers which are read from
a file
> in random order and needs to be sorted out in numerical order.
> e.g 7,10,1,5,.... into 1,2,3,....
> Below is some code to read the number from a file and display
them.
>
> Please help me sort them out.

You need to reassure people that this is not a homework
assignment, since it looks very like one. The code you
quote looks just like typical code that a professor would
give to students to get them started.

I don't think you will find people here ready to do you
assignments for you, the point of an assignment is to
figure out things for yourself.

If you have *specific* questions about things you read or try
and do not understand, then specific questions are most welcome.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Sort, was Re: HELP WITH SIMPLE PROGRAM PLEASE
  2000-04-17  0:00 HELP WITH SIMPLE PROGRAM PLEASE ashraf2000
  2000-04-17  0:00 ` Ted Dennison
  2000-04-17  0:00 ` Robert Dewar
@ 2000-04-18  0:00 ` Alfred Hilscher
  2 siblings, 0 replies; 4+ messages in thread
From: Alfred Hilscher @ 2000-04-18  0:00 UTC (permalink / raw)




ashraf2000@x-stream.co.uk wrote:
> 
> HI,
> 
> I am a beginner and trying to sort numbers which are read from a file
> in random order and needs to be sorted out in numerical order.
> e.g 7,10,1,5,.... into 1,2,3,....
> Below is some code to read the number from a file and display them.
> 
> Please help me sort them out.
> begin
> read;
> check;
> output;

Ok. What you have is quite good. You read the data and you write them.
The remaining part is to sort them. Your procedure check is a good
starting point. You check two number and if they are in the wrong order
you swap them. So do this not only for no(1) and no(2) but do it for all
numbers until they are ascending. For more information on sorting
algorithms you should look into the literature, e.g. Wirth's "Algorithm
and datastructures".




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-04-18  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-17  0:00 HELP WITH SIMPLE PROGRAM PLEASE ashraf2000
2000-04-17  0:00 ` Ted Dennison
2000-04-17  0:00 ` Robert Dewar
2000-04-18  0:00 ` Sort, was " Alfred Hilscher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox