tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
17
Task/Priority-queue/OCaml/priority-queue-1.ocaml
Normal file
17
Task/Priority-queue/OCaml/priority-queue-1.ocaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module PQ = Base.PriorityQueue
|
||||
|
||||
let () =
|
||||
let tasks = [
|
||||
3, "Clear drains";
|
||||
4, "Feed cat";
|
||||
5, "Make tea";
|
||||
1, "Solve RC tasks";
|
||||
2, "Tax return";
|
||||
] in
|
||||
let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in
|
||||
List.iter (PQ.add pq) tasks;
|
||||
while not (PQ.is_empty pq) do
|
||||
let _, task = PQ.first pq in
|
||||
PQ.remove_first pq;
|
||||
print_endline task
|
||||
done
|
||||
22
Task/Priority-queue/OCaml/priority-queue-2.ocaml
Normal file
22
Task/Priority-queue/OCaml/priority-queue-2.ocaml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
module PQSet = Set.Make
|
||||
(struct
|
||||
type t = int * string (* pair of priority and task name *)
|
||||
let compare = compare
|
||||
end);;
|
||||
|
||||
let () =
|
||||
let tasks = [
|
||||
3, "Clear drains";
|
||||
4, "Feed cat";
|
||||
5, "Make tea";
|
||||
1, "Solve RC tasks";
|
||||
2, "Tax return";
|
||||
] in
|
||||
let pq = List.fold_right PQSet.add tasks PQSet.empty in
|
||||
let rec aux pq' =
|
||||
if not (PQSet.is_empty pq') then begin
|
||||
let prio, name as task = PQSet.min_elt pq' in
|
||||
Printf.printf "%d, %s\n" prio name;
|
||||
aux (PQSet.remove task pq')
|
||||
end
|
||||
in aux pq
|
||||
Loading…
Add table
Add a link
Reference in a new issue