RosettaCodeData/Task/Priority-queue/OCaml/priority-queue-2.ocaml

23 lines
520 B
Text
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
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
2015-11-18 06:14:39 +00:00
let pq = PQSet.of_list tasks in
2013-04-10 23:57:08 -07:00
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