Oberon || Library || Module Index || Search Engine || Definition || Module
TYPE List = POINTER TO ListRec; TYPE ListRec = RECORD (Objects.ObjectRec) END; TYPE Element = POINTER TO ElementRec; TYPE ElementRec = RECORD (Objects.ObjectRec) END; TYPE CompareProc = PROCEDURE (e1: Element; e2: Element) : INTEGER;
PROCEDURE CreateList(VAR list: List); PROCEDURE CreateSortedList(VAR list: List; compare: CompareProc); PROCEDURE Add(list: List; element: Element); PROCEDURE Insert(list: List; element: Element); PROCEDURE First(list: List); PROCEDURE Next(list: List; VAR element: Element) : BOOLEAN; PROCEDURE Last(list: List); PROCEDURE Previous(list: List; VAR element: Element) : BOOLEAN;
List elements are of type Element. This datatype is to be extended with the informations to be stored into the list.
CreateList creates a (unsorted) list. list serves as reference for future operations. CreateSortedList creates a sorted list.
Add adds the given element to list. element is either appended or in case of sorted lists inserted according to the order defined by compare. Insert works like Add but inserts the given element prior to the head in case of unsorted lists.
Next and Previous allow sequential access of list in ascending resp. descending order. Each call of Next or Previous works relative to the element returned previously. First causes Next or Previous to return the first element of list. This is the historically first element for unsorted lists (if the list was built up by calls of Add) or the lowest element in case of sorted lists. Likewise, Last positions to the last element. First and Last return FALSE at the end of the list.
VAR list: Lists.List; element: Lists.Element; (* ... *) Lists.First(list); WHILE Lists.Next(list, element) DO (* ... *) END;
Oberon || Library || Module Index || Search Engine || Definition || Module