comp.lang.ada
 help / color / mirror / Atom feed
From: Arthur Schwarz <schwarza@gdls.com>
To: dwheeler@ida.org
Subject: Re: Linked list problem
Date: 1997/02/19
Date: 1997-02-19T00:00:00+00:00	[thread overview]
Message-ID: <330B96EB.5BA5@gdls.com> (raw)
In-Reply-To: 5ed9gc$6v0@news.ida.org


Dave;

   The correct answer depends on the list characteristics. 

   [1] If you have a singly linked list whose last element is a pointer
to NULL
       then something like:

          new.pointer  := NULL;
          last.pointer := new;

       or more generally:

         new.pointer   := last.pointer;
         last.pointer  := new;

       should work.

   [2] If you have a singly linked list with a list with a header, then
       a. if the list is above and the header points to the first and
last
          element, the header has to be altered.
       b. If the last element on the list points to the first element on
          the list and the header points to the first and last element, 
          see (a).
       c. If the last element of the list points to the list header, and
          the list header points to the first and last element of the
          list, then see (a).

   (in general) etc., etc., ...

   And if you do have a list header, make sure that that an insertion
into
   the list recognizes that the insertion may be to an empty list.

   And if you don't have a list header, just an initial pointer to the
first
   element of a list, make sure (as above) that you care for inserting a
new
   list element to an empty list.

   (Sorry about my Ada!)

   I hope some of this helps! 

art schwarz

David Wheeler wrote:
> 
> Blake C Weston (blake@dedlock.demon.co.uk) wrote:
> : I have a slight problem. I have been trying to append one linked list to
> : another. Unfortunately try as I might, I cannot get the algorithm to
> : work correctly.
> 
> : As far as I understand, the method by which you append lists is to
> : simply make the last node of the list you are appending to 'point' to
> : the first node of the other list.
> 
> Correct.
> 
> You can learn more about how to access types from lesson 12 of Lovelace,
> an Ada95 tutorial.  You can go directly to lesson 12 by using
> a web browser to open:
>  http://www.adahome.com/Tutorials/Lovelace/lesson12.htm
> 
> You can start at the beginning of Lovelace by opening:
>  http://www.adahome.com/Tutorials/Lovelace/lovelace.htm
> 
> A book version of the Lovelace tutorial will soon be available,
> probably by the end of March 1997.
> The book version will have a number of errors removed and will be
> easier to read (useful if you plan to read all of it).
> 
> --- David A. Wheeler
>     dwheeler@ida.org




      reply	other threads:[~1997-02-19  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-15  0:00 Linked list problem Blake C Weston
1997-02-15  0:00 ` Bob Klungle
1997-02-18  0:00 ` David Wheeler
1997-02-19  0:00   ` Arthur Schwarz [this message]
replies disabled

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