comp.lang.ada
 help / color / mirror / Atom feed
From: "Nick Roberts" <Nick.Roberts@dial.pipex.com>
Subject: Re: Simple Student Problem Ada83
Date: 1997/04/20
Date: 1997-04-20T00:00:00+00:00	[thread overview]
Message-ID: <01bc4dc5$207eacc0$f4f582c1@xhv46.dial.pipex.com> (raw)
In-Reply-To: 01bc4cd3$f8a7fae0$9bfd1fcc@p5120.bda




Bob Klungle <grbg@junque.com> wrote in article
<01bc4cd3$f8a7fae0$9bfd1fcc@p5120.bda>...
> Several possibilities come to mind without thinking much. No elegance,
just
> hack.
[hackish solution]

Alternatively,

(a) suppose the array is called A

(b) suppose the number of valid components in A at any particular time is
in n

(c) suppose the component of A to be deleted is number i

a slightly less hackish solution might go along these lines:

(1) check that i is not greater than n (what should we do if it is?)

(2) copy the components from A(i+1..n) into A(i..n-1)

(3) decrement n

I will leave coding this into Ada as an exercise, since this is supposed to
be an exercise for you! Answer the question posed at the end of (1) - it is
an important question.

Also, answer the following question. The copy in (2) will be implemented by
Ada as a loop, copying the machine elements, let's say bytes, of the array
slice specified. This loop will have two 'byte pointers' addressing the
byte to be copied from and the byte to be copied to. There are two possible
schemes: (1) both pointers are set at their respective last bytes to be
copied, and both are decremented; (2) both pointers are set to their
respective first bytes and both incremented. Which scheme - (1) or (2) -
will be used in this particular example, and why?

Nick.





  parent reply	other threads:[~1997-04-20  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-19  0:00 Simple Student Problem Ada83 mrbunny
     [not found] ` <01bc4cd3$f8a7fae0$9bfd1fcc@p5120.bda>
1997-04-20  0:00   ` Nick Roberts [this message]
1997-04-21  0:00     ` Robert Dewar
replies disabled

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