From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ebf338b64557dbd2 X-Google-Attributes: gid103376,public From: Arthur Schwarz Subject: Re: Linked list problem Date: 1997/02/19 Message-ID: <330B96EB.5BA5@gdls.com>#1/1 X-Deja-AN: 219984457 References: <5ed9gc$6v0@news.ida.org> To: dwheeler@ida.org Content-Type: text/plain; charset=us-ascii Organization: General Dynamics Land Systems Mime-Version: 1.0 Newsgroups: comp.lang.ada X-Mailer: Mozilla 3.01 (X11; I; SunOS 5.4 sun4m) Date: 1997-02-19T00:00:00+00:00 List-Id: 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