Oberon || Library || Module Index || Search Engine || Definition || Module

Ulm's Oberon Library:


Lists - management of linear lists


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;


Lists supports double linked lists. Lists may be optionally maintained in sorted order. Sorted lists need a comparison procedure of type CompareProc. Comparison procedures compare e1 against e2 and return a negative integer value if e1 is less than e2, zero if e1 equals e2, and a positive integer value if e1 is greater than e2.

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.


Following code fragment examines a list in ascending order:
   list: Lists.List;
   element: Lists.Element;

(* ... *)

WHILE Lists.Next(list, element) DO
   (* ... *)


Lists will be replaced by a more general set of modules in the future.
Edited by: borchert, last change: 1994/02/12, revision: 1.4, converted to HTML: 1997/04/28

Oberon || Library || Module Index || Search Engine || Definition || Module