Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
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 = PQSet.of_list tasks 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