Priority queue: Difference between revisions

Content added Content deleted
Line 5,140: Line 5,140:
)
)
</pre>
</pre>

=={{header|Picat}}==
Picat has built-in support for min and max heaps.
<lang Picat>main =>
Tasks = [[3,"Clear drains"],
[4,"Feed cat"],
[5,"Make tea"],
[1,"Solve RC tasks"],
[2,"Tax return"]],
Heap = new_min_heap([]),
foreach(Task in Tasks)
Heap.heap_push(Task),
println(top=Heap.heap_top())
end,
nl,
println(Heap),
println(size=Heap.heap_size),
nl,
println("Pop the elements from the queue:"),
println([Heap.heap_pop() : _ in 1..Heap.heap_size]).</lang>

{{out}}
<pre>top = [3,Clear drains]
top = [3,Clear drains]
top = [3,Clear drains]
top = [1,Solve RC tasks]
top = [1,Solve RC tasks]

_$heap(5,{[1,Solve RC tasks],[2,Tax return],[5,Make tea],[4,Feed cat],[3,Clear drains],_33c8},min)
size = 5

Pop the elements from the queue:
[[1,Solve RC tasks],[2,Tax return],[3,Clear drains],[4,Feed cat],[5,Make tea]]</pre>

The heaps creation functions can take the task list as argument:
<lang Picat> Tasks = [[3,"Clear drains"],
[4,"Feed cat"],
[5,"Make tea"],
[1,"Solve RC tasks"],
[2,"Tax return"]],
Heap = new_min_heap(Tasks),
println([Heap.heap_pop() : _ in 1..Heap.heap_size]).</lang>



=={{header|PicoLisp}}==
=={{header|PicoLisp}}==