Ajout Stack.top

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@3072 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 2000-04-13 12:16:02 +00:00
parent a5eafc35c6
commit e27406829f
2 changed files with 8 additions and 0 deletions

View File

@ -27,6 +27,11 @@ let pop s =
hd::tl -> s.c <- tl; hd
| [] -> raise Empty
let top s =
match s.c with
hd::_ -> hd
| [] -> raise Empty
let length s = List.length s.c
let iter f s = List.iter f s.c

View File

@ -29,6 +29,9 @@ val push: 'a -> 'a t -> unit
val pop: 'a t -> 'a
(* [pop s] removes and returns the topmost element in stack [s],
or raises [Empty] if the stack is empty. *)
val top: 'a t -> 'a
(* [top s] returns the topmost element in stack [s],
or raises [Empty] if the stack is empty. *)
val clear : 'a t -> unit
(* Discard all elements from a stack. *)
val length: 'a t -> int