.TH "Stack" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME Stack \- Last-in first-out stacks. .SH Module Module Stack .SH Documentation .sp Module .BI "Stack" : .B sig end .sp Last\-in first\-out stacks\&. .sp This module implements stacks (LIFOs), with in\-place modification\&. .sp .sp .sp .I type .B 'a .I t .sp The type of stacks containing elements of type .B \&'a \&. .sp .I exception Empty .sp Raised when .B Stack\&.pop or .B Stack\&.top is applied to an empty stack\&. .sp .I val create : .B unit -> 'a t .sp Return a new stack, initially empty\&. .sp .I val push : .B 'a -> 'a t -> unit .sp .B push x s adds the element .B x at the top of stack .B s \&. .sp .I val pop : .B 'a t -> 'a .sp .B pop s removes and returns the topmost element in stack .B s , or raises .B Stack\&.Empty if the stack is empty\&. .sp .I val top : .B 'a t -> 'a .sp .B top s returns the topmost element in stack .B s , or raises .B Stack\&.Empty if the stack is empty\&. .sp .I val clear : .B 'a t -> unit .sp Discard all elements from a stack\&. .sp .I val copy : .B 'a t -> 'a t .sp Return a copy of the given stack\&. .sp .I val is_empty : .B 'a t -> bool .sp Return .B true if the given stack is empty, .B false otherwise\&. .sp .I val length : .B 'a t -> int .sp Return the number of elements in a stack\&. Time complexity O(1) .sp .I val iter : .B ('a -> unit) -> 'a t -> unit .sp .B iter f s applies .B f in turn to all elements of .B s , from the element at the top of the stack to the element at the bottom of the stack\&. The stack itself is unchanged\&. .sp .I val fold : .B ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b .sp .B fold f accu s is .B (f (\&.\&.\&. (f (f accu x1) x2) \&.\&.\&.) xn) where .B x1 is the top of the stack, .B x2 the second element, and .B xn the bottom element\&. The stack is unchanged\&. .sp .B "Since" 4.03 .sp