comp.lang.ada
 help / color / mirror / Atom feed
From: "Zeg" <zeg.nospam@9online.fr>
Subject: chained List manipulation without recusrsion : lost the begining of my List!
Date: Thu, 15 May 2003 01:20:42 +0200
Date: 2003-05-15T01:20:42+02:00	[thread overview]
Message-ID: <b9uj25$bfv$1@aphrodite.grec.isp.9tel.net> (raw)

Hi all,
I'm trying to make a procedure to insert an integer (at this natural
position) in a chained List without recursion but
each time I lost the begining of my List, i understand why but i don't find
the trick.

I think it would be very easy for most of you,
Thanks in Advance .
                                        Zeg

  type Element is new Integer;

   type Maillon;

   type Liste is access Maillon;

   type Maillon is record
      Valeur  : Element;
      Suivant : Liste := null;
   end record;


procedure Insert_iteratif(E : in Element; L : in out Liste) is
Aux : Liste := L;
Z : Liste := null;
begin
      if (Aux = null) then
         Aux := new Maillon'(E,null);
      else
         while  (Aux /= null) loop
              if (Aux.all.valeur > E) then
                  L := new Maillon'(E,Aux);
                  exit;
            elsif (Aux.all.suivant = null) then
                  L:= new Maillon'(E,null);
                  exit;
            end if;
            z := Aux ;
            Aux := Aux.all.suivant;
         end loop;
     end if;

end Insert_iteratif;

--========================
begin
L := new Maillon'( 3,new Maillon'(4,new Maillon'(5,new Maillon'(7,new
Maillon'(8,new Maillon'(10,new Maillon'(99,null)))))));
Insert_iteratif(9,L);

end
 --=======================





             reply	other threads:[~2003-05-14 23:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-14 23:20 Zeg [this message]
2003-05-15  5:58 ` chained List manipulation without recusrsion : lost the begining of my List! Simon Wright
2003-05-15 12:25   ` Zeg
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