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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,100c539a37d7d2e6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-15 12:05:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3EC3E50D.1000004@spam.com> From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: chained List manipulation without recusrsion : lost the begining of my List! References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 15 May 2003 19:02:56 GMT NNTP-Posting-Host: 63.184.32.95 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1053025376 63.184.32.95 (Thu, 15 May 2003 12:02:56 PDT) NNTP-Posting-Date: Thu, 15 May 2003 12:02:56 PDT Xref: archiver1.google.com comp.lang.ada:37364 Date: 2003-05-15T19:02:56+00:00 List-Id: Zeg wrote: > I missed inserting at the head of the List so this the > > ultimate code I've reformatted it to help me understand it, used consistent capitalization, added some blank lines and removed others, and removed unnecessary parentheses and ".all"s. This was to help me more than anything, but good formatting and consistent capitalization are generally a Good Thing. It's usually not a Good Idea to use tabs for indentation; 2-4 blanks is usually good. > > procedure Insert_iteratif (E : in Element; L : in out Liste) is > Aux : Liste := L; > Z : Liste; > begin Do you check your precondition (L is sorted) anywhere? > if L = null then > L := new Maillon'(E, null); > else > while Aux /= null loop > if Aux.Valeur > E then > if Z = null then > L := new Maillon'(E, L); > else > Z.Suivant := new Maillon'(E, Aux); > end if; > > exit; > elsif Aux.suivant = null then > Z.Suivant := new Maillon'(E, null); At the end of the list. It seems to me that it is possible for Z to be null here, for example if L has exactly 1 element. > > exit; > end if; > > Z := Aux; > Aux := Aux.Suivant; > end loop; > end if; > end Insert_iteratif; It seems you've missed the case of adding to the end of a single-element list. It would be clearer what you're doing if you used names such as "Current" and "Previous" rather than "Aux" and "Z". (You might prefer French equivalents.) You don't need to put parentheses around conditions, the way you have to in some languages. Nor do you have to put ".all" when referencing a component of something designated by an access value. This is part of the idea of allowing something to change from statically allocated to dynamically allocated (or from dynamic to static) without having to add or remove a bunch of ".all"s. -- Jeff Carter "I'm a lumberjack and I'm OK." Monty Python's Flying Circus