comp.lang.ada
 help / color / mirror / Atom feed
From: "Zeg" <zeg.nospam@9online.fr>
Subject: Re: chained List manipulation without recusrsion : lost the begining of my List!
Date: Thu, 15 May 2003 14:25:47 +0200
Date: 2003-05-15T14:25:47+02:00	[thread overview]
Message-ID: <ba0129$dg9$1@apollon.grec.isp.9tel.net> (raw)
In-Reply-To: x7vfzngg39y.fsf@smaug.pushface.org

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2308 bytes --]

Got it!!
It's a really good exercise to understand pointers and recursivity!
Thanks.

procedure Insert_iteratif(E : in Element; L : in out Liste) is

Aux : Liste := L;

Z : Liste;

begin

                if (L = null) then

            L := new Maillon'(E,null);

                else

                                while (Aux /= null) loop

                                            if (Aux.all.valeur > E) then

                      z.all.suivant := new Maillon'(E,Aux);

                                                            exit;

                                             elsif (Aux.all.suivant = null)
then

                       z.all.suivant := new Maillon'(E,null);

                                                              exit;

                                             end if;


           z := Aux ;

                              Aux := Aux.all.suivant;


                            end loop;

                end if;


end Insert_iteratif;

"Simon Wright" <simon@pushface.org> a �crit dans le message de
news:x7vfzngg39y.fsf@smaug.pushface.org...
> "Zeg" <zeg.nospam@9online.fr> writes:
>
> > procedure Insert_iteratif(E : in Element; L : in out Liste) is
> > Aux : Liste := L;
> > Z : Liste := null;
>
> You don't need to initialize access variables, they are automatically
> set to null for you
>
> > begin
> >       if (Aux = null) then
> >          Aux := new Maillon'(E,null);
>
> L was empty, so what is it pointing to now? Should you have altered it?
>
> >       else
> >          while  (Aux /= null) loop
> >               if (Aux.all.valeur > E) then
> >                   L := new Maillon'(E,Aux);
>
> What has happened to all the previous elements in the list? (that L
> used to be pointing to)
>
> >                   exit;
> >             elsif (Aux.all.suivant = null) then
> >                   L:= new Maillon'(E,null);
>
> What has happened to all the previous elements in the list?
>
> >                   exit;
> >             end if;
> >             z := Aux ;
>
> What is Z for? You don't read it anywhere
>
> >             Aux := Aux.all.suivant;
> >          end loop;
> >      end if;
> >
> > end Insert_iteratif;
>
> It might help you to draw a picture of Maillons linked into a Liste,
> and how you want a new Maillon to be linked in.





  reply	other threads:[~2003-05-15 12:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-14 23:20 chained List manipulation without recusrsion : lost the begining of my List! Zeg
2003-05-15  5:58 ` Simon Wright
2003-05-15 12:25   ` Zeg [this message]
2003-05-15 13:16   ` Zeg
2003-05-15 19:02     ` Jeffrey Carter
2003-05-16  1:11   ` Robert A Duff
2003-05-17  7:03     ` Simon Wright
replies disabled

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