Package Double_Lists

package for generic double linked list

Class Data_Element

generic type instancieded by Double_List. This is the type which have the to stored elements of Double_List.

Class Double_List

throws Empty_List_Exception .

Class for generic double linked list. It includes methods for Add_At_Tail, Add_At_Head, Remove, Get_Data and get the last, next, previous and first element. Empty_List_Exception is thrown, if you access Double_List and Double_List is null. (Use Is_Empty to check it)

Attributes

private Double_Lists.Internal_List Anchor_First 

Access to first element of Double_List

private Double_Lists.Internal_List Anchor_Last 

Access to last element of Double_List

private Double_Lists.Internal_List Anchor_Cursor 

Pointer to element at cursor of Double_List

Operations

public Add_At_Head ( Double_Lists.Data_Element Item );

Insert Item in the Double_List as first element. This means: Get_Data(First(Double_List, Add_At_Head(Double_List, Item)))=Item. Cursor is anywhere in list, if list is not empty.

public Add_At_Tail ( Double_Lists.Data_Element Item );

Insert Item in the Double_List as last element. This means: Get_Data(Last(Double_List, Add_At_Tail(Double_List, Item)))=Item. Cursor is anywhere in list, if list is not empty.

public Double_Lists.Data_Element Get_Data (void);

Returns the element at internal cursor position.

public Remove (void);

Deletes element at cursor position. Was it the old last one, the old previous one is the new last one and there stands the cursor after Remove. Otherwise the cursor stands at old next one after Remove.

public First (void);

Sets the cursor at first position in Double_List.

public Last (void);

Sets the cursor at last position in Double_List.

public Next (void);

Sets the cursor at next position in Double_List. To Iterate Double_List forward use the follow algorithm: L: Double_List; E: Data_Element; First(L); -- Set the internal Iterator at first Position while not Is_Empty(L) loop -- Is the Iterator in the List? E:= Get_Data(L); -- do somthing with this datas Next(L); -- Set the internal Iterator at the next Element of List end loop; -- now is the internal Iterator "behind" the List -- GetData(L) should raise a exception First(L); -- fetchs the internal Iterator back in List (here to the -- beginning of the List)

public Previous (void);

Sets the cursor at previous position in Double_List.

public Boolean Is_Empty ( Boolean Check_Internal_List := True );

returns true if Double_List has no element and otherwiese false

public Remove ( Double_Lists.Data_Element Element );

Deletes given element. If the element is several times in the list, only the first copy is removed.

Class Internal_List

throws Empty_List_Exception .

Class for generic double linked list. It includes methods for Add_at_Head, Add_At_Tail, Remove, Get_Data and get the next, previous element.

Attributes

private Double_Lists.Data_Element Data 

Element at current position

private Double_Lists.Internal_List Previous 

Access to previous element of Internal_List

private Double_Lists.Internal_List Next 

Access to next element of Internal_List

Operations

private Add_At_Head ( Double_Lists.Data_Element Item , Double_Lists.Internal_List First , Double_Lists.Internal_List Last );

Insert Item in the Double_List as first element. This means: Get_Data(First(Double_List, Add_At_Head(Double_List, Item)))=Item. Internal cursor is undefined after this, but stand at the list, if the list is not empty.

private Add_At_Tail ( Double_Lists.Data_Element Item , Double_Lists.Internal_List First , Double_Lists.Internal_List Last );

Insert Item in the Double_List as last element. This means: Get_Data(Last(Double_List, Add_At_Tail(Double_List, Item)))=Item. internal cursor is undefined after this, but stand at the list, if the list is not empty.

private Double_Lists.Data_Element Get_Data (void);

Returns the element at internal cursor position.

private Remove ( Double_Lists.Internal_List First , Double_Lists.Internal_List Last );

Deletes element at cursor position. Was it the old last one, the old previous one is the new last one and there stands the cursor after Remove. Otherwise the cursor stands at old next one after Remove.

private Next (void);

Sets the cursor at next position in Double_List.

private Previous (void);

Sets the cursor at previous position in Double_List.

private Boolean Is_Empty (void);

returns true if Double_List has no element and otherwiese false

private Boolean Has_Next (void);

returns true if Double_List has next element and otherwiese false

private Boolean Has_Previous (void);

returns true if Double_List has previous element and otherwiese false

private Destroy ( Double_Lists.Internal_List First , Double_Lists.Internal_List Last );

Destructor