Double linked List

"Create a generic container. The elements in this container are iterateable both forward and backward. It means you can access at next, previous, fist and last element in O(1). "

Figure 10-2. Double linked List Overview

Double List Diagram

Mechanics

Double_List is reasoned at Internal_List and Double_List

Internal_List is the core of this double linked list. Each Internal_List hold a previous pointer and the next pointer besides the actual Data. So you can iterate this list with Previous and Next. But objects of this class "do not know" the first and last element.

So the Double_List holds one Internal_List which is represented the current Position in the list in Anchor_Cursor. Additionally Double_List is kept the first and last position in the list in Anchor_First and Anchor_Last respectively. Now there exists 3 types of Methods:

Role of Is_Empty

Is_Empty means here that the cursor is not in List. An access to the Anchor_Cursor (this represents the position pointer in the List) e.g. with Get_Data raised an Empty_List_Exception. Note:You have to gurantee that position of the cursor "is in list". If you have at least one element in the list you can do that with First or Last

Iterate the List

To Iterate the list forward set the cursor at first position in the list with First. Now you can iterate the list with Next while you in list (check it with Is_Empty. If you want to access this list later do not forget to set the cursor back into list with First or Last!

To Iterate the list backward set the cursor at first position in the list with Last. Now you can iterate the list with Previous while you in list (check it with Is_Empty. If you want to access this list later do not forget to set the cursor back into list with First or Last!