Continuing our previous discussion on Recursive Objects, Data structures use of this properties and Accesses to deal with data memory management.
Sometimes you want it to be fast, sometimes robust, and sometimes you balance many small factors. This is why there are so many different structures.
package Linked_Lists is
type Link is limited private;
procedure Add (List : in out Link;
Datum : in Boolean);
procedure Print_All (List: in Link);
subtype List_Type is Link;
private
type Node;
type Link is access Node;
type Node is record
Datum : Boolean;
Next : Link;
--Prev : Link;
end record;
end Linked_Lists;
with Ada.Text_IO;
package body Linked_Lists is
procedure Add (List : in out Link;
Datum : in Boolean) is
Aux_Link : Link;
begin
Aux_Link := new Node;
Aux_Link.Datum := Datum ;
Aux_Link.Next := List;
List := Aux_Link ;
end Add;
procedure Print_All (List: in List_Type) is
Aux_Link : Link;
begin
Aux_Link := List;
while Aux_Link /= null loop
Ada.Text_IO.Put_Line (Boolean'Image(Aux_Link.Datum));
Aux_Link := Aux_Link.Next;
end loop;
end Print_All;
end Linked_Lists;