Doubly-linked list/Element definition: Difference between revisions

Content added Content deleted
Line 11: Line 11:
Data : Integer;
Data : Integer;
end record;
end record;
</lang>
Using generics, the specification might look like this:
<lang ada>
generic
type Element_Type is private;
package Linked_List is
type List_Type is limited private;
...
private
type List_Element;
type List_Element_Ptr is access list_element;
type List_Element is
record
Prev : List_Element_Ptr;
Data : Element_Type;
Next : List_Element_Ptr;
end record;
type List_Type is
record
Head : List_Element_Ptr; -- Pointer to first element.
Tail : List_Element_Ptr; -- Pointer to last element.
Cursor : List_Element_Ptr; -- Pointer to cursor element.
Count : Natural := 0; -- Number of items in list.
Traversing : Boolean := False; -- True when in a traversal.
end record;
end Linked_List;
</lang>
</lang>
In Ada 2005 this example can be written without declaration of an access type:
In Ada 2005 this example can be written without declaration of an access type:
Line 23: Line 49:


Ada's standard container library includes a generic doubly linked list. The structure of the link element is private.
Ada's standard container library includes a generic doubly linked list. The structure of the link element is private.

=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
<pre>MODE LINK = STRUCT (
<pre>MODE LINK = STRUCT (