From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: sort function
Date: Fri, 4 May 2001 16:49:03 GMT
Date: 2001-05-04T16:49:03+00:00 [thread overview]
Message-ID: <3AF2DD7F.6832E7D9@boeing.com> (raw)
In-Reply-To: 3AF2A5F8.63668DBD@brighton.ac.uk
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
next prev parent reply other threads:[~2001-05-04 16:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-04 12:52 sort function sc297
2001-05-04 15:05 ` Simon Pilgrim
2001-05-04 16:49 ` Jeffrey Carter [this message]
2001-05-08 15:21 ` John English
2001-05-09 5:44 ` tmoran
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox