tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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