1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the GNU Library General Public License, with *)
10 (* the special exception on linking described in file ../LICENSE. *)
12 (***********************************************************************)
14 (* $Id: stack.mli 7164 2005-10-25 18:34:07Z doligez $ *)
16 (** Last-in first-out stacks.
18 This module implements stacks (LIFOs), with in-place modification.
22 (** The type of stacks containing elements of type ['a]. *)
25 (** Raised when {!Stack.pop} or {!Stack.top} is applied to an empty stack. *)
28 val create : unit -> 'a t
29 (** Return a new stack, initially empty. *)
31 val push : 'a -> 'a t -> unit
32 (** [push x s] adds the element [x] at the top of stack [s]. *)
35 (** [pop s] removes and returns the topmost element in stack [s],
36 or raises [Empty] if the stack is empty. *)
39 (** [top s] returns the topmost element in stack [s],
40 or raises [Empty] if the stack is empty. *)
42 val clear : 'a t -> unit
43 (** Discard all elements from a stack. *)
45 val copy : 'a t -> 'a t
46 (** Return a copy of the given stack. *)
48 val is_empty : 'a t -> bool
49 (** Return [true] if the given stack is empty, [false] otherwise. *)
51 val length : 'a t -> int
52 (** Return the number of elements in a stack. *)
54 val iter : ('a -> unit) -> 'a t -> unit
55 (** [iter f s] applies [f] in turn to all elements of [s],
56 from the element at the top of the stack to the element at the
57 bottom of the stack. The stack itself is unchanged. *)