Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
20
Task/Queue-Definition/OCaml/queue-definition-1.ocaml
Normal file
20
Task/Queue-Definition/OCaml/queue-definition-1.ocaml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module FIFO : sig
|
||||
type 'a fifo
|
||||
val empty: 'a fifo
|
||||
val push: fifo:'a fifo -> item:'a -> 'a fifo
|
||||
val pop: fifo:'a fifo -> 'a * 'a fifo
|
||||
val is_empty: fifo:'a fifo -> bool
|
||||
end = struct
|
||||
type 'a fifo = 'a list * 'a list
|
||||
let empty = [], []
|
||||
let push ~fifo:(input,output) ~item = (item::input,output)
|
||||
let is_empty ~fifo =
|
||||
match fifo with
|
||||
| [], [] -> true
|
||||
| _ -> false
|
||||
let rec pop ~fifo =
|
||||
match fifo with
|
||||
| input, item :: output -> item, (input,output)
|
||||
| [], [] -> failwith "empty fifo"
|
||||
| input, [] -> pop ([], List.rev input)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue