restructure + lecutre 07

This commit is contained in:
SowinskiBraeden committed 2026-02-19 11:59:58 -08:00
1 parent b8c19aa341
commit 7c3198fee4
96 files changed
+458 -4

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
"Rule: ocaml dependencies ml (%=two_list_queue )": "\153s\252\225.\205\197\1597\030\142\254Q\213.\135"
"Resource: /home/flami/Projects/comp3958/lecture06/two_list_queue.ml": "\174\189*\255(\166==\251\006\232\150\141\1714\130"
"Rule: ocaml: ml -> cmo & cmi (%=two_list_queue )": "9\165\179\031F'#6\127\149\136<\242y\019t"
+8
View File
@@ -0,0 +1,8 @@
### Starting build.
# Target: /home/flami/.opam/default/bin/ocamlc.opt -config, tags: { }
/home/flami/.opam/default/bin/ocamlc.opt -config
# Target: two_list_queue.ml.depends, tags: { extension:ml, file:two_list_queue.ml, ocaml, ocamldep, quiet }
/home/flami/.opam/default/bin/ocamldep.opt -modules two_list_queue.ml > two_list_queue.ml.depends
# Target: two_list_queue.cmo, tags: { byte, compile, extension:cmo, extension:ml, file:two_list_queue.cmo, file:two_list_queue.ml, implem, ocaml, quiet }
/home/flami/.opam/default/bin/ocamlc.opt -c -o two_list_queue.cmo two_list_queue.ml
# Compilation successful.
+42
View File
@@ -0,0 +1,42 @@
(* queue is empty iff the first list is empty *)
type 'a t = 'a list * 'a list;;
exception Empty;;
let empty = ([], []);;
let is_empty (l, _) = l = [];;
let enqueue x (l1, l2) =
match l1 with
| [] -> [x], l2
| _ -> (l1, x :: l2);;
let dequeue (l1, l2) =
match l1 with
| [] -> raise Empty
| [_] -> (List.rev l2, [])
| _ :: xs -> (xs, l2);;
let dequeue_opt q =
try
Some (dequeue q)
with
| Empty -> None;;
let front (l, _) =
match l with
| [] -> raise Empty
| x :: _ -> x;;
let front_opt (l, _) =
match l with
| [] -> None
| x :: _ -> Some x;;
let of_list l =
List.fold_left (Fun.flip enqueue) empty l;;
let to_list (l1, l2) =
l1 @ List.rev l2;;
@@ -0,0 +1 @@
two_list_queue.ml: Fun List