Traverse from the beginning of a doubly-linked list to the end, and from the end to the beginning.



See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


 
MODULE Collections;
IMPORT Box;
 
TYPE
  Action = PROCEDURE (o: Box.Object);
 
        PROCEDURE (dll: DLList) GoForth*(do: Action);
	VAR
		iter: Node;
	BEGIN
		iter := dll.first;
		WHILE iter # NIL DO
			do(iter.value);
			iter := iter.next
		END
	END GoForth;
 
	PROCEDURE (dll: DLList) GoBack*(do: Action);
	VAR
		iter: Node;
	BEGIN
		ASSERT(dll.last # NIL);
		iter := dll.last;
		WHILE iter # NIL DO
			do(iter.value);
			iter := iter.prev
		END
	END GoBack;
 
END Collections.
 