RosettaCodeData/Task/Priority-queue/Standard-ML/priority-queue.ml

30 lines
605 B
OCaml
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
structure TaskPriority = struct
type priority = int
val compare = Int.compare
type item = int * string
val priority : item -> int = #1
end
structure PQ = LeftPriorityQFn (TaskPriority)
;
let
val tasks = [
(3, "Clear drains"),
(4, "Feed cat"),
(5, "Make tea"),
(1, "Solve RC tasks"),
(2, "Tax return")]
2013-10-27 22:24:23 +00:00
val pq = foldl PQ.insert PQ.empty tasks
2013-04-10 23:57:08 -07:00
(* or val pq = PQ.fromList tasks *)
fun aux pq' =
case PQ.next pq' of
NONE => ()
| SOME ((prio, name), pq'') => (
print (Int.toString prio ^ ", " ^ name ^ "\n");
aux pq''
)
in
aux pq
end