Modula-2 || Compiler & Tools || Library || Search Engine


Ulm's Modula-2 Library:
Stack


NAME

Stack - store any objects in lifo-manner

SYNOPSIS

TYPE Stack; 


PROCEDURE Create (VAR stack : Stack; noelem : CARDINAL; example : ARRAY OF BYTE); PROCEDURE Dispose (VAR stack : Stack); PROCEDURE Clear(stack : Stack); PROCEDURE Elems (stack : Stack) : CARDINAL; PROCEDURE Push (stack : Stack; elem : ARRAY OF BYTE) : BOOLEAN; PROCEDURE Pop (stack : Stack; VAR elem : ARRAY OF BYTE) : BOOLEAN; PROCEDURE Top(stack : Stack; pos : CARDINAL; VAR elem : ARRAY OF BYTE) : BOOLEAN; PROCEDURE Adr(stack : Stack; pos : CARDINAL; VAR adr : ADDRESS) : BOOLEAN;

DESCRIPTION

This module supports storage of objects on a stack realized by type Stack. Create creates and allocates a stack stack for noelem elements. The type of the objects to be stored derives from example which must be of the same kind than the data stored subsequently. Dispose deallocates stack, Clear empties it and Elems returns the number of elements currently stored.

Push and Pop behave in the expected manner. Push puts a further element elem onto stack Pop gets the element stored at last and removes it from the stack.

Top yields the last but pos'th element pushed onto stack without removing it.

An object on stack may be accessed by its storage address obtained from Adr, which sets adr to the address of the last but pos'th element stacked.

Using Top or Adr, pos = 0 always refers to the element on top of stack.

DIAGNOSTICS

All procedures check overflow and underflow conditions and return FALSE in these cases. Stack access may also fail if the parameters elem are not of a suitable type.

AUTHOR

Werner Stanglow
Edited by: borchert, last change: 1997/02/25, revision: 1.2, converted to HTML: 1997/04/28

Modula-2 || Compiler & Tools || Library || Search Engine