Priority queue: Difference between revisions

Content added Content deleted
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 5.10.0;
<syntaxhighlight lang="perl">use strict;
use strict;
use warnings;
use feature 'say';
use Heap::Priority;
use Heap::Priority;


my $h = new Heap::Priority;
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>output<syntaxhighlight lang="text">Make tea
say while ($_ = $h->pop);</syntaxhighlight>
{{out}}
<pre>
Make tea
Feed cat
Feed cat
Clear drains
Clear drains
Tax return
Tax return
Solve RC tasks</syntaxhighlight>
Solve RC tasks
</pre>
===IBM card sorter version===
<syntaxhighlight lang="perl">#!/usr/bin/perl


===IBM card sorter version===
use strict; # https://rosettacode.org/wiki/Priority_queue
<syntaxhighlight lang="perl">use strict;
use warnings; # in homage to IBM card sorters :)
use warnings; # in homage to IBM card sorters :)