module Make:
Parameters: |
|
type
t
exception Empty
val create : unit -> t
Create a new empty stack.
val singleton : D.t -> t
Create a new qstack with a single element.
val is_empty : t -> bool
Test whether the stack is empty or not.
val clear : t -> unit
Remove all the elements of a stack.
val add : D.t -> t -> unit
Add at the beginning of the stack. Complexity: O(1).
val add_at_end : D.t -> t -> unit
Add at the end of the stack. Complexity: O(1).
val top : t -> D.t
Return the top element of the stack. Raise Empty
if the stack is
empty. Complexity: amortized O(1).
val mem : D.t -> t -> bool
Return true
if the data exists in the stack and false
otherwise.
Complexity: O(n).
val filter : (D.t -> bool) -> t -> D.t list
Return all data of the stack satisfying the specified predicate. The order of the data in the input stack is preserved. Not tail recursive.
val find : (D.t -> bool) -> t -> D.t
Return the first data of the stack satisfying the specified predicate.
Not_found
if there is no such data in the stackval remove : D.t -> t -> unit
Remove an element from the stack. Complexity: O(n).
val move_at_top : D.t -> t -> unit
Move the element x
at the top of the stack s
.
Complexity: O(n).
Invalid_argument
if not (mem x s)
.val move_at_end : D.t -> t -> unit
Move the element x
at the end of the stack s
.
Complexity: O(n).
Invalid_argument
if not (mem x s)
.val iter : (D.t -> unit) -> t -> unit
Iter on all the elements from the top to the end of the stack. Not tail recursive.
val map : (D.t -> D.t) -> t -> unit
Replace in-place all the elements of the stack by mapping the old one. Not tail recursive.
val fold : ('a -> D.t -> 'a) -> 'a -> t -> 'a
Fold on all the elements from the top to the end of the stack. Not tail recursive.
val nth : int -> t -> D.t
Invalid_argument
if there is not enough element in the stack.val length : t -> int
val idx : D.t -> t -> int
Not_found
if the element is not in the stack
This function is not tail recursive