Priority queue: Difference between revisions
Content deleted Content added
add Ada |
No edit summary |
||
Line 339: | Line 339: | ||
{4 Feed cat} |
{4 Feed cat} |
||
{5 Make tea} |
{5 Make tea} |
||
</pre> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
|||
This solution uses classes provided by the UniLib package. |
|||
<tt>Heap</tt> is an implementation of a priority queue and |
|||
<tt>Closure</tt> is used to allow the queue to order lists based on |
|||
their first element. The solution only works in Unicon. |
|||
<lang Unicon>import Utils # For Closure class |
|||
import Collections # For Heap (dense priority queue) class |
|||
procedure main() |
|||
pq := Heap(, Closure("[]",Arg,1) ) |
|||
pq.add([3, "Clear drains"]) |
|||
pq.add([4, "Feed cat"]) |
|||
pq.add([5, "Make tea"]) |
|||
pq.add([1, "Solve RC tasks"]) |
|||
pq.add([2, "Tax return"]) |
|||
while task := pq.get() do write(task[1]," -> ",task[2]) |
|||
end |
|||
</lang> |
|||
Output when run: |
|||
<pre> |
|||
1 -> Solve RC tasks |
|||
2 -> Tax return |
|||
3 -> Clear drains |
|||
4 -> Feed cat |
|||
5 -> Make tea |
|||
</pre> |
</pre> |
||