1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../LICENSE. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Last-in first-out stacks.
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2005-10-25 11:34:07 -07:00
|
|
|
This module implements stacks (LIFOs), with in-place modification.
|
2001-10-26 16:33:00 -07:00
|
|
|
*)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
type 'a t
|
2001-12-03 14:16:03 -08:00
|
|
|
(** The type of stacks containing elements of type ['a]. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
exception Empty
|
2001-12-03 14:16:03 -08:00
|
|
|
(** Raised when {!Stack.pop} or {!Stack.top} is applied to an empty stack. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2001-10-26 16:33:00 -07:00
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val create : unit -> 'a t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return a new stack, initially empty. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val push : 'a -> 'a t -> unit
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [push x s] adds the element [x] at the top of stack [s]. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val pop : 'a t -> 'a
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [pop s] removes and returns the topmost element in stack [s],
|
|
|
|
or raises [Empty] if the stack is empty. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val top : 'a t -> 'a
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [top s] returns the topmost element in stack [s],
|
|
|
|
or raises [Empty] if the stack is empty. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val clear : 'a t -> unit
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Discard all elements from a stack. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val copy : 'a t -> 'a t
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return a copy of the given stack. *)
|
|
|
|
|
2002-06-27 01:48:26 -07:00
|
|
|
val is_empty : 'a t -> bool
|
|
|
|
(** Return [true] if the given stack is empty, [false] otherwise. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val length : 'a t -> int
|
2001-10-26 16:33:00 -07:00
|
|
|
(** Return the number of elements in a stack. *)
|
|
|
|
|
2001-12-03 14:16:03 -08:00
|
|
|
val iter : ('a -> unit) -> 'a t -> unit
|
2001-10-26 16:33:00 -07:00
|
|
|
(** [iter f s] applies [f] in turn to all elements of [s],
|
|
|
|
from the element at the top of the stack to the element at the
|
|
|
|
bottom of the stack. The stack itself is unchanged. *)
|