Priority queue: Difference between revisions
Content added Content deleted
(→{{header|Pascal}}: advanced version) |
m (→Advanced version: cosmetic) |
||
Line 5,295: | Line 5,295: | ||
====Advanced version==== |
====Advanced version==== |
||
{{works with|FPC}} |
{{works with|FPC}} |
||
A maximizing priority queue based on a binary heap with the ability to update keys using a special handle. User is responsible for keeping track of when the handle becomes invalid. |
A maximizing priority queue based on a binary heap with the ability to update keys using a special handle. User is responsible for keeping track of when the handle becomes invalid. Comparing elements requires a regular boolean function of the form: |
||
Comparing elements requires a regular boolean function of the form: |
|||
<syntaxhighlight lang="pascal"> |
<syntaxhighlight lang="pascal"> |
||
type |
type |
||
TComparer<T> = function(const L, R: T): Boolean; |
TComparer<T> = function(const L, R: T): Boolean; |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
which should return True if the first argument is less than the second. |
which should return True if the first argument is less than the second. It seems that all operations should be performed in O(NLogN). |
||
<syntaxhighlight lang="pascal"> |
<syntaxhighlight lang="pascal"> |
||
unit PQueue; |
unit PQueue; |
||
Line 5,541: | Line 5,540: | ||
<syntaxhighlight lang="pascal"> |
<syntaxhighlight lang="pascal"> |
||
program PqDemo; |
program PqDemo; |
||
{$mode delphi |
{$mode delphi} |
||
uses |
uses |
||
SysUtils, PQueue; |
SysUtils, PQueue; |