Priority queue: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: future-proof for 5.36) |
|||
Line 5,981: | Line 5,981: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
===Using a Module=== |
|||
There are a few implementations on CPAN. Following uses <code>Heap::Priority</code>[http://search.cpan.org/~fwojcik/Heap-Priority-0.11/Priority.pm] |
There are a few implementations on CPAN. Following uses <code>Heap::Priority</code>[http://search.cpan.org/~fwojcik/Heap-Priority-0.11/Priority.pm] |
||
<syntaxhighlight lang="perl">use |
<syntaxhighlight lang="perl">use strict; |
||
use |
use warnings; |
||
use feature 'say'; |
|||
use Heap::Priority; |
use Heap::Priority; |
||
my $h = |
my $h = Heap::Priority->new; |
||
$h->highest_first(); # higher or lower number is more important |
$h->highest_first(); # higher or lower number is more important |
||
Line 5,995: | Line 5,997: | ||
["Tax return", 2]; |
["Tax return", 2]; |
||
say while ($_ = $h->pop);</syntaxhighlight> |
say while ($_ = $h->pop);</syntaxhighlight> |
||
{{out}} |
|||
<pre> |
|||
Make tea |
|||
Feed cat |
Feed cat |
||
Clear drains |
Clear drains |
||
Tax return |
Tax return |
||
Solve RC tasks |
Solve RC tasks |
||
</pre> |
|||
⚫ | |||
⚫ | |||
⚫ | |||
use strict; # https://rosettacode.org/wiki/Priority_queue |
|||
⚫ | |||
use warnings; # in homage to IBM card sorters :) |
use warnings; # in homage to IBM card sorters :) |
||