comp.lang.ada
 help / color / mirror / Atom feed
* chained List manipulation without recusrsion : lost the begining of my List!
@ 2003-05-14 23:20 Zeg
  2003-05-15  5:58 ` Simon Wright
  0 siblings, 1 reply; 7+ messages in thread
From: Zeg @ 2003-05-14 23:20 UTC (permalink / 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
 --=======================





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2003-05-17  7:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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