STACK create_stack(null_elem)

- create a new stack ST_ELEMENT null_elem;

void destroy_stack(s)

- delete a stack STACK s;

void push(s, e)

- push an element on the stack STACK s; ST_ELEMENT e;

ST_ELEMENT pop(s)

- pop the top element of the stack STACK s;

ST_ELEMENT top(s)

- return the top element of the stack STACK s;

Bool on_stack(s, e)

- check if element is on the stack STACK s; ST_ELEMENT e;

int stack_size(s)

- return the number of elements on the stack STACK s;

int stack_is_empty(s)

- check if stack is empty STACK s;

void stack_print(file, s)

- print the entire stack FILE *file; STACK s;

These general functions define a generic datatype stack. ST_ELEMENT and STACK and every function that is needed, must be defined as macro's for the C pre-processor when this file is included. For different stacks the same procedures can be used. This module can handle stacks for integers but also for characters, structures, floats etc.

To create a stack create_stack() is used, the user can define its own null_elem which is returned by top() and pop() if the stack is empty. destroy_stack() destroys the stack. push() pushes a new element on the stack. pop() pops the topelement of the stack and returns the value of this element When the stack is empty the null-element is returned. top() returns the topelement when there is one otherwise the null-element is returned. The element is not popped of the stack.

on_stack() returns TRUE if e is on the stack and FALSE otherwise. To determine whether an element is on the stack, e is compared with all the stackelements using the function ST_EQUALKEY. This is also a user defined macro. The number of elements on the stack is returned by stack_size(), stack_is_empty() returns TRUE when the stack is empty and when the stack does not exists.

To print a stack a procedure print_elem() must be defined which prints the elements. The top is printed first.

stack.gen stack.gh