comp.lang.ada
 help / color / mirror / Atom feed
* sort function
@ 2001-05-04 12:52 sc297
  2001-05-04 15:05 ` Simon Pilgrim
  2001-05-04 16:49 ` Jeffrey Carter
  0 siblings, 2 replies; 5+ messages in thread
From: sc297 @ 2001-05-04 12:52 UTC (permalink / raw)


help . ive written a sort funtion, but for the life of me i cant work
out what i have done wrong. help me ada people

with ada.text_io, ada.integer_text_io;
use ada.text_io, ada.integer_text_io;


procedure sort( Data: in out Vector ) is
Type Vector is array( Positive Range <> ) of Integer;


temp : integer:=0;
status : boolean := false;
swap:integer:=0;
Begin
while status /= true loop
  For I in data'first..data'last-1 loop
    If data(I)>data(I+1) then
      temp:=data(I);
      data(I):=data(I+1);
      data(I+1):=temp;
        swap:=swap+1;
    Else
      Null;
    End if;

    If swap = 0 then
      Status := true;
    Else
      Status:=false;
    End if;
  End loop;
swap:=0;
End loop;
End sort;




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

* Re: sort function
  2001-05-04 12:52 sort function sc297
@ 2001-05-04 15:05 ` Simon Pilgrim
  2001-05-04 16:49 ` Jeffrey Carter
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Pilgrim @ 2001-05-04 15:05 UTC (permalink / raw)




sc297 wrote:
> 
> help . ive written a sort funtion, but for the life of me i cant work
> out what i have done wrong. help me ada people
> 
> with ada.text_io, ada.integer_text_io;
> use ada.text_io, ada.integer_text_io;
> 
> procedure sort( Data: in out Vector ) is
> Type Vector is array( Positive Range <> ) of Integer;

You need to declare Vector before you use it.  You could wrap it all in
a package, but this will only get it to compile.  To make something
useful, you need to get some data into Data (BTW it is best to avoid
such generic names for types and variables to avoid confusion).

From the look of your program, I guess you aren't too familiar with
text_io.  Have a look at the examples on www.adapower.com and if you are
still baffled, go and ask your lecturer for help.  They probably already
know you've posted here since at least one of the staff from Brighton is
a regular poster here.

Try and be more specific with your problem descriptions.  Most of the
people in this NG use Ada for their jobs and only read the NG while at
work, so make it easy for us to help you.

-- 
Regards,
Simon Pilgrim
BAE SYSTEMS, Civil Flight Controls, Rochester UK



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

* Re: sort function
  2001-05-04 12:52 sort function sc297
  2001-05-04 15:05 ` Simon Pilgrim
@ 2001-05-04 16:49 ` Jeffrey Carter
  2001-05-08 15:21   ` John English
  1 sibling, 1 reply; 5+ messages in thread
From: Jeffrey Carter @ 2001-05-04 16:49 UTC (permalink / raw)


sc297 wrote:
> 
> help . ive written a sort funtion, but for the life of me i cant work
> out what i have done wrong. help me ada people
> 
> with ada.text_io, ada.integer_text_io;
> use ada.text_io, ada.integer_text_io;

You never use anything from these packages, so why with and use them?

> 
> procedure sort( Data: in out Vector ) is

Here you reference type Vector, which is undefined (a type declaration
must occur before you can reference it).

> Type Vector is array( Positive Range <> ) of Integer;

Here you define type Vector, but it's too late.

> 
> temp : integer:=0;
> status : boolean := false;
> swap:integer:=0;
> Begin
> while status /= true loop

If you rewrite this as

loop
   exit when Status;


you can see that Status needs a better name, like Done or Finished.

>   For I in data'first..data'last-1 loop
>     If data(I)>data(I+1) then
>       temp:=data(I);
>       data(I):=data(I+1);
>       data(I+1):=temp;
>         swap:=swap+1;
>     Else
>       Null;
>     End if;
> 
>     If swap = 0 then
>       Status := true;
>     Else
>       Status:=false;
>     End if;

This if can be replaced by

Status := Swap = 0;

which is clearer.

>   End loop;
> swap:=0;
> End loop;
> End sort;

It looks to me as if Swap is really a Boolean.

You should ask John English about this. That's what he's there for.

--
Jeffrey Carter



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

* Re: sort function
  2001-05-04 16:49 ` Jeffrey Carter
@ 2001-05-08 15:21   ` John English
  2001-05-09  5:44     ` tmoran
  0 siblings, 1 reply; 5+ messages in thread
From: John English @ 2001-05-08 15:21 UTC (permalink / raw)


Jeffrey Carter wrote:
> You should ask John English about this. That's what he's there for.

This is what I tell people every year, but nothing ever changes... :-)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



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

* Re: sort function
  2001-05-08 15:21   ` John English
@ 2001-05-09  5:44     ` tmoran
  0 siblings, 0 replies; 5+ messages in thread
From: tmoran @ 2001-05-09  5:44 UTC (permalink / raw)


> > You should ask John English about this. That's what he's there for.
>
> This is what I tell people every year, but nothing ever changes... :-)
  Perhaps you need a T-shirt with something along the lines
    Faster than a newsgroup
    Nicer than a newsgroupie.
    X-Ray vision to see through confusion
    It's Professor English in room ...!



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

end of thread, other threads:[~2001-05-09  5:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-05-04 12:52 sort function sc297
2001-05-04 15:05 ` Simon Pilgrim
2001-05-04 16:49 ` Jeffrey Carter
2001-05-08 15:21   ` John English
2001-05-09  5:44     ` tmoran

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