comp.lang.ada
 help / color / mirror / Atom feed
* circularity and symetrical list
@ 1999-09-23  0:00 J.M.
  1999-09-23  0:00 ` tmoran
  1999-09-23  0:00 ` Robert Dewar
  0 siblings, 2 replies; 3+ messages in thread
From: J.M. @ 1999-09-23  0:00 UTC (permalink / raw)


Does anybody know who i can declare a circularity and symetrical list
or anybody can tell me if my structure is good : (sorry my english is
very bad ! )

Type Type_Maillon;

Type Type_Ptr is access Type_Maillon;

Type Type_Maillon is record
    Info : Type_Element ;
    Next  : Type_Ptr ;
    Precedent   : Type_Ptr ;
End record;


Procedure Free is new Unchecked_Deallocation (Type_Maillon,
Type_Ptr);
    
Procedure Vider (L : in out Type_Ptr) is
-- Ant : /
-- Cons : clean list
Link : Type_Ptr;
Begin 
    While L /= null loop
        Link := L;
        L.Precedent.Next := L.Next;
        L.Next.Precedent := L.Precedent;
        Free (Link);
    End loop;
End Vider;


Function Find_Node (L : in Type_Ptr ; i : in Positive) return
Type_Ptr is
-- Ant�c�dent : /
-- Cons�quent : find ptr(i)
Indice : Positive;
Link : Type_Ptr;
Begin -- Find_Node
    If i <= 0 then
        Return null;
    Else
        Indice := 1;
        Link := L.Next;
        While (Indice /= i) and (Link /= L) loop
            Indice := Indice + 1;
            Link := Link.Next;
        End loop;
        If Indice = i then
            Return Link;
        Else
            Return null;
        End if;
    End if;
End Find_Node;


Procedure Inserer (L : in out Type_Ptr ; Item : in Type_Commande)
is
-- Ant�c�dent : /
-- Cons�quent : insert Item(i)
Link1, Link2 : Type_Ptr;
Begin -- Inserer
    Link1 := Find_Node(L,i);
    If ((i>0) and (Link1 /= Null)) or (i=0) then
        Link2 := New Type_Maillon;
        Link2.Info := Item;
        If i=0 then -- ins�rer en t�te de liste
            Link2.Next := L.Next;
            L.Next := Link2;
        Else
            Link2.Next := Link1.Next;
            Link1.Next := Link2;
        End if;
    End if;
End Inserer;






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

end of thread, other threads:[~1999-09-23  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-23  0:00 circularity and symetrical list J.M.
1999-09-23  0:00 ` tmoran
1999-09-23  0:00 ` Robert Dewar

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