module Make:
| Parameters: |
|
type t
exception Empty
val create : unit -> tCreate a new empty stack.
val singleton : D.t -> tCreate a new qstack with a single element.
val is_empty : t -> boolTest whether the stack is empty or not.
val clear : t -> unitRemove all the elements of a stack.
val add : D.t -> t -> unitAdd at the beginning of the stack. Complexity: O(1).
val add_at_end : D.t -> t -> unitAdd at the end of the stack. Complexity: O(1).
val top : t -> D.tReturn the top element of the stack. Raise Empty if the stack is
empty. Complexity: amortized O(1).
val mem : D.t -> t -> boolReturn true if the data exists in the stack and false otherwise.
Complexity: O(n).
val filter : (D.t -> bool) -> t -> D.t listReturn 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.tReturn 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 -> unitRemove an element from the stack. Complexity: O(n).
val move_at_top : D.t -> t -> unitMove 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 -> unitMove 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 -> unitIter on all the elements from the top to the end of the stack. Not tail recursive.
val map : (D.t -> D.t) -> t -> unitReplace in-place all the elements of the stack by mapping the old one. Not tail recursive.
val fold : ('a -> D.t -> 'a) -> 'a -> t -> 'aFold on all the elements from the top to the end of the stack. Not tail recursive.
val nth : int -> t -> D.tInvalid_argument if there is not enough element in the stack.val length : t -> intval idx : D.t -> t -> intNot_found if the element is not in the stack
This function is not tail recursive