14 lines
368 B
OCaml
14 lines
368 B
OCaml
open List
|
|
open Exposed
|
|
|
|
let enqueue (a : 'a) (qu : 'a queue) : 'a queue =
|
|
{ qu with front = a :: qu.back }
|
|
|
|
let dequeue (qu : 'a queue) : ('a option * 'a queue) =
|
|
match qu.front with
|
|
| [a] -> (Some a, { front = List.reverse qu.back; back = [] })
|
|
| h :: t -> (Some h, { qu with front = t })
|
|
| [] -> (None, qu)
|
|
|
|
let empty = { front = []; back = [] }
|