Module Stack (.ml)


module Stack: sig .. end
imperative stack


Types

exception OVERFLOW
thrown if a stack exceeds the system given maximum size.
type 'a stack 
the stack

Functions


Creation


val create : 'a -> 'a stack
create null_element creates an empty stack. null element must be provided.
val clear : 'a stack -> unit
empties the stack

Status


val is_empty : 'a stack -> bool
empty stack?
val size : 'a stack -> int
the stack size

Access


val push : 'a stack -> 'a -> unit
pushs an element onto the stack.
Raises OVERFLOW if the stack is full.
val top : 'a stack -> 'a
returns the top element of the stack.
Raises Not_found if the stack is empty.
val pop : 'a stack -> 'a
removes and returns the top element of the stack.
Raises Not_found if the stack is empty.
val remove_top : 'a stack -> unit
removes the top element of the stack.
Raises Not_found if the stack is empty.

Iteration


val iter : ('a -> unit) -> 'a stack -> unit
visits each stack element in order from bottom to top, i.e. the top element is visited last.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b stack -> 'a
visits each stack element in order from bottom to top, i.e. the top element is visited last.
val iter_stop : ('a -> unit) -> ('a -> bool) -> 'a stack -> unit
iter_stop apply stop like iter, but stop the traversal if stop is true on a stack element. stop is checked before apply.
val map : ('a -> 'a) -> 'a stack -> 'a stack
clones the stack.

Sorting


val sort : ('a -> 'a -> int) -> 'a stack -> unit
sorts the stack.
val find : 'a stack -> ('a -> int) -> 'a
find stack check finds the element specified by check.

stack must be sorted according to an ordering. check delivers the result of this ordering for the search for element and any stack element. it returns 0, if the stack element is equal to the searchecd element, -1, if the stack element is greater, +1 otherwise.